What is missing here to read the sent value into my_input and break the loop in tok2.py? Now it runs forever.
Using Debian 10 Buster with Python 3.7.
Using Debian 10 Buster with Python 3.7.
# tok1.py
import sys
import time
import subprocess
command = [sys.executable, 'tok2.py']
proc = subprocess.Popen(command, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
i=0
while proc.poll() is None:
if i > 5:
#Send BreakLoop after 5th iteration
proc.stdin.write(b'exit')
print('tok1: ' + str(i))
time.sleep(0.5)
i=i+1#tok2.py
import sys
import time
ii=0
my_input =''
while True:
my_input = sys.stdin.read()
if my_input == b'exit':
print('tok2: exiting')
sys.stdout.flush()
break
print('tok2: ' + str(ii))
sys.stdout.flush()
ii=ii+1
time.sleep(0.5)
