Note that there are some explanatory texts on larger screens.

plurals
  1. POProblems communicating between Node.js and Python via stdio
    text
    copied!<p>I'm spawning a Node process from within a Python thread and passing data between them via stdio. After Python sends something to Node, Node fires up a child process and then sends the output from that child process back to Python.</p> <p>This works, for a few seconds and then no more data comes. However, if I kill the Node process, then suddenly all of the data comes at once.</p> <p>I figure this is something to do with buffering but I've tried so many things and can't get it to work properly.</p> <p>It's worth mentioning that if I run the monitor outside of Python it works fine, so this is probably something on the Python side.</p> <p>Relevant Python code:</p> <pre><code>class MonitorThread(Thread): # *snip* def run(self): self.process = Popen(['node', path.join(PACKAGE_PATH 'monitor.js')], stdout=PIPE, stdin=PIPE, stderr=PIPE) while self.process.poll() is None: stdout = self.process.stdout.readline().rstrip('\n') if stdout: main_thread(debug, stdout) stderr = self.process.stderr.readline().rstrip('\n') if stderr: main_thread(debug, stderr) #time.sleep(0.1) </code></pre> <p>Relevant Node.js code (in CoffeeScript but even if you don't know it you get the idea):</p> <pre><code># *snip* child = spawn cmd, options child.stdout.on 'data', (data) -&gt; process.stdout.write "stdout: #{data.toString().trim()}\n" child.stderr.on 'data', (data) -&gt; process.stdout.write "stderr: #{data.toString().trim()}\n" </code></pre> <p>There's a lot of other code but it's not really relevant, data is being sent and then afterwards data is being received, just only for a moment. It IS still running as when I kill it manually, the rest of the data suddenly appears.</p> <pre><code>Monitor [send] - {"wrap": false, "directories": {"src": "lib"}, "id": 0, "base_dir": "C:\\Users\\Joe\\Documents\\GitHub\\CoffeeScript-Sublime-Plugin"} Monitor [recv] - 13:55:30 - compiled src\a.coffee Monitor [recv] - path.exists is now called `fs.exists`. Monitor [recv] - 13:55:30 - compiled src\b.coffee </code></pre> <ul> <li>I've tried util.pump()</li> <li>I've tried, with the spawn() call, stdio: 'inherit'</li> <li>I've tried waiting for the 'drain' event before sending more data.</li> </ul>
 

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