Tuesday, 9 May 2017

How to call endless python script from NodeJS

I have a python script:

//test.py

import psutil

while True:
    result = psutil.cpu_percent(interval=1)
    print(result)

and then nodejs code:

//test.js
    var PythonShell = require('python-shell')
    pyshell = new PythonShell('test.py')
    pyshell.on('message', function(message) {
        console.log(message)
    })

nothing happened when I executing node script. Please help me how to get data per second (like "real-time") from endless python code from Node and loggging it to console.



via Anh Quoc Tran

No comments:

Post a Comment