-
Notifications
You must be signed in to change notification settings - Fork 221
Closed
Labels
Description
The Question:
The following code snippet is taken straight from your README file.
import {PythonShell} from 'python-shell';
let options = {
mode: 'text',
pythonPath: 'path/to/python',
pythonOptions: ['-u'], // get print results in real-time
scriptPath: 'path/to/my/scripts',
args: ['value1', 'value2', 'value3']
};
PythonShell.run('my_script.py', options, function (err, results) {
if (err) throw err;
// results is an array consisting of messages collected during execution
console.log('results: %j', results);
});
However, you fail to specify who catches the thrown err and where.
If I wrap the PythonShell.run code block like so
try {
PythonShell.run('my_script.py', options, function (err, results) {
if (err) throw err;
// results is an array consisting of messages collected during execution
console.log('results: %j', results);
});
}
catch(error) {
console.log(error);
}
Nothing prints out.
-
How am I supposed to throw an error using the callback function?
-
How am I supposed to catch an error?
Thank you!