- Code: Select all
#client.py: test client for communicating with wrapper.py
from subprocess import Popen, PIPE
from threading import Thread
from time import sleep
def read_it():
print(u"read_it thread running")
while True:
for msg in process.stdout:
print(u"subprocess output: {}".format(msg.rstrip()))
print(u"subprocess starting")
process = Popen(['/usr/bin/python3', './wrapper.py', 'arg1, 'arg2'],
stdin=PIPE, stdout=PIPE, close_fds=True, bufsize=1, universal_newlines=True)
print(u"subprocess running: {}".format(process.pid))
thread = Thread(target=read_it)
thread.daemon = True
thread.start()
sleep(5.0) # wait for initial output from subprocess
When this run using Python3, it works as expected:
- Code: Select all
% /usr/bin/python3 --version
Python 3.8.2
% /usr/bin/python3 ./client.py
subprocess starting
subprocess running: 24458
read_it thread running
subprocess output: {"msg": "status", "status": "Login Complete"}
But not when running using Python2:
- Code: Select all
% /usr/bin/python --version
Python 2.7.16
% /usr/bin/python ./client.py
subprocess starting
subprocess running: 24466
read_it thread running
Both processes are definitely running, I'm checking that in another Terminal window.
Any ideas?