pkrumins / node-tree-kill

kill trees of processes
MIT License
333 stars 37 forks source link

Does not work properly in Windows #40

Open joshua-classen opened 2 years ago

joshua-classen commented 2 years ago

I spawn a python Process in my Electron App. On the python process runs a Flask server. In my Electron App I spawn the Python process with

const { spawn } = require('child_process');
const treeKill = require('tree-kill');
const path = require('path');

const projectPath = path.join(__dirname, '../');
const pathToPython = path.join(projectPath, '/Venv/Scripts/python');
const pythonOptions = [path.join(projectPath, '/pythonBackend/app.py')];

let ls = spawn(pathToPython, pythonOptions);

I later kill the process with

treeKill(ls.pid);

I can see in the Process Explorer from Microsoft that the tree also gets killed,but after a milisecond, the python process somehow respawns as a standalone process.

If I kill the exact same process tree in the Process Explorer from Windows, then the tree gets killed and there is no crazy respawn of the python process. I don't know why its respawning with the tree-kill module. Any Ideas?

UPDATE I use now the module tree-kill-promise. https://www.npmjs.com/package/tree-kill-promise This worked for me.

xxshady commented 2 years ago

wtf xdddd its basically the same code https://github.com/dword-design/tree-kill-promise/blob/3d2ca856e1bc3d55d967d9a3eebd516615c086b2/src/index.js#L3

madaono commented 1 year ago

get the same problems, the java process somehow respawns as a standalone process. await this.findAvailablePort(PRINT_SERVER_PORT); const childPrintProcess = child_process.spawn('cmd.exe', [ '/c', jrePath, '-jar', '-Dfile.encoding=UTF-8', -Dserver.port=${this.availablePort}`, '-Ddisable.waiter=merge_table,temp_dish,campaign_dish,old_combo,member_center,full_reduce,charge_quit', '-Ddisable.link.upgrade=true', printServicePath, ]); this.printSocketProcess = childPrintProcess.pid;

// some thing treeKill(this.printSocketProcess, 'SIGKILL', resolve); `