Repeatedly write to STDIN and read STDOUT of a Subprocess without closing it
<p>I am trying to employ a Subprocess in Python for keeping an external script open in a Server-like fashion. The external script first loads a model. Once this is done, it accepts requests via STDIN and returns processed strings to STDOUT.</p>

<p>So far, I've tried</p>

<pre><code>tokenizer = subprocess.Popen([tokenizer_path, '-l', lang_prefix], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
</code></pre>

<p>However, I cannot use</p>

<pre><code>tokenizer.stdin.write(input_string+'\n')
out = self._tokenizer.stdout.readline()
</code></pre>

<p>in order to repeatedly process input_strings by means of the subprocess – out will just be empty, no matter if I use <code>stdout.read()</code> or <code>stdout.readline()</code>. However, it works when I close the stdin with <code>tokenizer.stdin.close()</code> before reading STDOUT, but this closes the subprocess, which is not what I want as I would have to reload the whole external script again before sending another request.</p>

<p>Is there any way to use a subprocess in a server-like fashion in python without closing and re-opening it?</p>
