Advertisement
Guest User

Untitled

a guest
Aug 18th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. import sys
  2. import time
  3. import subprocess
  4.  
  5. command = [sys.executable, 'tok2.py']
  6. proc = subprocess.Popen(command, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  7.  
  8. i=0
  9. while proc.poll() is None:
  10. if i > 5:
  11. #Send 'exit' after 5th iteration
  12. proc.stdin.write(b'exit')
  13.  
  14. print('tok1: ' + str(i))
  15.  
  16. time.sleep(0.5)
  17. i=i+1
  18.  
  19. import sys
  20. import time
  21.  
  22. ii=0
  23. my_input =''
  24. while True:
  25. my_input = sys.stdin.read()
  26.  
  27. if my_input == b'exit':
  28. print('tok2: exiting')
  29. sys.stdout.flush()
  30. break
  31.  
  32. print('tok2: ' + str(ii))
  33. sys.stdout.flush()
  34. ii=ii+1
  35. time.sleep(0.5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement