-
-
Save djangosporti/8ba00fc074e19b54d734973271ac1e94 to your computer and use it in GitHub Desktop.
Long running Python Parent/Child communication via pipes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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