I'm making an interactive CLI in node (and blessed.js) that spawns child processes every couple of seconds to run some Python scripts. These scripts modify a set of JSON files that the CLI pulls from.
The problem is that the CLI must be able to accept input from the user at all times, and when these child processes are spawned, the stdin of the CLI/parent process appears to be blocked and it looks like the Python scripts are executing in the foreground. Here's the code I'm using to run the Python scripts:
const { spawn } = require("child_process");
function execPythonScript(args) {
return spawn("python3", args, { stdio: "ignore" });
}
execPythonScript(["path_to_script.py"]);
I've also tried running the script as a background process, i.e. execPythonScript(["path_to_script.py", "&"]), but to no avail. Any ideas?
Thanks in advance!
UPDATE:
I'm starting to suspect this is an issue with blessed and not child-process, since I've exhausted all relevant methods (and their arguments) for spawning non-blocking background processes, and the problem still persists.
Each blessed instance uses process.stdin for input by default, but I figured it's possible that the stdin stream gets used up by the child processes, even though I'm spawning them with stdio set to "ignore". So I tried using ttys and instantiating blessed.screen to read from the active terminal (/dev/tty) instead of /dev/stdin:
const ttys = require("ttys");
screen = blessed.screen({
input: ttys.stdin, // Instead of process.stdin
smartCSR: true
});
But it's still blocking...