Skip to content

Instantly share code, notes, and snippets.

@dvirsky
Created November 19, 2014 11:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dvirsky/f9ebf6f66f763a356d4a to your computer and use it in GitHub Desktop.
Save dvirsky/f9ebf6f66f763a356d4a to your computer and use it in GitHub Desktop.
Long running Python Parent/Child communication via pipes
import subprocess
import time
import sys
def parent():
p = subprocess.Popen(['python', './testp.py', '--child'], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
i = 0
while True:
i+=1
p.stdin.write("Hello %d\r\n" % i)
print "Got: ", p.stdout.readline().strip('\r\n')
time.sleep(0.1)
def child():
while True:
x= raw_input()
print x
if __name__ == '__main__':
if '--child' in sys.argv:
child()
else:
parent()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment