Skip to content

Instantly share code, notes, and snippets.

@bign8
Created January 25, 2017 06:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bign8/803bfd9c82a58828bb4df04c08be11d8 to your computer and use it in GitHub Desktop.
Save bign8/803bfd9c82a58828bb4df04c08be11d8 to your computer and use it in GitHub Desktop.
Python output streaming
console.log('running');
var child = require('child_process').spawn('python', ['./index.py']);
child.stdout.on('data', function(data) {
console.log('stdout: "' + data.toString().trim() + '"');
});
child.stderr.on('data', function(data) {
console.log('stderr: ' + data);
});
child.on('close', function(code) {
console.log('closing code: ' + code);
});
import time, sys
def step(name):
print(name)
sys.stdout.flush() # the key
time.sleep(1)
for name in ['five', 'four', 'three', 'two', 'one']:
step(name)
print('blastoff!')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment