在我的应用程序中,我正在从nodejs生成python进程
在执行大约15的负载测试时,遇到此错误。
nodejs有多个函数正在调用该过程
我正在使用centos8和python 3.6.x
这是我的目录结构
/path/to/my/app/src/dboperations/db/<all the python files here>
这是完整的错误
/usr/bin/python3: can't open file '/path/to/my/app/src/dboperations/db/myPyFile.py': [Errno 2] No such file or directory
这是我的代码
const python = spawn(process.env.pythonPath, [__dirname+'/db/' + pyFile, JSON.stringify(recievedData)]); //pyfile is the name of the file
python.stdout.on('data', function (data) {
dataToSend = dataToSend + data.toString();
});
python.stderr.on('data', (data) => {
dataToSend = dataToSend + data;
});
python.on('close', (code) => {
if (code == 0) {
return dataToSend //success
}else{
return dataToSend //error
}
});
在输出中我得到了错误,
错误中提到的文件实际上在目录中,并且在先前的函数调用中成功运行了
我怀疑正在使用__dirname
是问题吗?
我有另一种方法来引用要生成的python文件的路径
const python = spawn(process.env.pythonPath, [process.cwd() +'/dboperations/db/'+ pyFile, JSON.stringify(recievedData)]);
有人可以帮我弄清楚这个错误吗?