Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This isn't really the best way to have interprocess communication, I recommend you either use the multiprocessing or threading libraries with something like either a Queue or PIPE for communication and synchronization.</p> <p>a Queue would be simplest way for sharing data, one process would put in a value and another would get the values.</p> <p>I've modified your original code so it works now, note that raw_input doesn't flush stdout as such if theres nothing there it will hang, <a href="http://code.activestate.com/lists/python-list/265749/" rel="nofollow">http://code.activestate.com/lists/python-list/265749/</a> which is why your code was just waiting for stdout ...</p> <p><b> THIS IS DANGEROUS, it can generate deadlocks, use at your own risk, try another method.</b> </p> <pre><code>import sys print 'Whats your favorite animal\n' #raw_input doesn't flush :( and we want to read in a whole line sys.stdout.flush() f = raw_input() print f </code></pre> <p>and the corresponding main.py</p> <pre><code>import subprocess, sys, os process = subprocess.Popen([sys.executable]+['example.py'], stdout = subprocess.PIPE, stderr = subprocess.PIPE, stdin = subprocess.PIPE) while True: if process.poll() != None: break request_input = process.stdout.readline() # read line, this will wait until there's actually a line to read. if request_input == "Whats your favorite animal\n": print 'request: %s sending: %s' % (request_input, 'cat') process.stdin.write('cat\n') process.stdin.flush() </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload