I am using child_process
model to send data to a python script, where I preform some calculations with pandas
, and then send it back to a node.js
script: index.js
. The problem is that when I import the pandas module to the python script, it stops the script from returning data to my index.js
script (I dont know why). However, if I simply dont import the pandas
module, i get data returned from the python script.
This is how i send the data to the python script from index.js
:
const spawn = require('child_process').spawn
let result = ''
const pythonProcess = spawn('python',['./rl-commands/t1.py', a, b]); #a, b are arguments that I send through. In this case they are just som integers (2 and 2)
Then I process the data in the python script like this (keep in mind i am not actually using pandas here, because I am just trying to make the connection between the two scripts work first, but pandas is still necessary):
import sys
import json
import random
import numpy as np
import pandas as pd
a = sys.argv[1]
b = sys.argv[2]
print(int(a) + int(b))
sys.stdout.flush()
Finally I retrieve the code that i processed in python to my index.js
script:
pythonProcess.stdout.on('data', (data) => {
result += data.toString()
});
pythonProcess.on('close', function (code) {
console.log("RES: ", result);
});
!!! As explained earlier, this does not work. But if I comment out the pandas import from the python script, it works:
import sys
import json
import random
import numpy as np
#import pandas as pd
a = sys.argv[1]
b = sys.argv[2]
print(int(a) + int(b))
sys.stdout.flush()
I dont understand how removing import pandas as pd
makes the script run?