Created
January 25, 2017 06:52
-
-
Save bign8/803bfd9c82a58828bb4df04c08be11d8 to your computer and use it in GitHub Desktop.
Python output streaming
This file contains 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
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); | |
}); |
This file contains 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 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