Node.js's python child script outputting on finish, not real time

有些话、适合烂在心里 提交于 2019-12-05 10:05:34

You need to disable output buffering in python. This can be done many different ways, including:

  • Setting the PYTHONUNBUFFERED environment variable
  • Passing the -u switch to the python executable
  • Calling sys.stdout.flush() after each write (or print() in your case) to stdout
  • For Python 3.3+ you can pass flush=true to print(): print('Hello World!', flush=True)

Additionally, in your node code, (even though you have a sleep in your python code and you are now flushing stdout) you really should not assume that output in your 'data' handler for thermostat.stdout is always going to be just one line.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!