1

Situation:

I am using multiprocessing.managers.BaseManager([address[, authkey]]) for python cross-process communication. I am having two scripts now, one serves as a base manager server which runs BaseManager.start() and one serves as a client to read the data from the server`.

Obstacle:

When I run the server script, two python.exe with different PID can be seen from my Windows Task Manager. As I can understand, one is the main(parent) process and one is the spawned subprocess from BaseMange.start(). This is fine.

I found that if I kill the main process' python.exe the BaseManager's python.exe will still be alive.

Reason that I am doing this is because I need to launch/ kill python scripts form NodeJS using require(child-process).spawn which will only kill the main process.

According to the documentation. It says Manager processes will be shutdown as soon as they are garbage collected or their parent process exits which does not match what I've seen from Windows Task Manager. Providing detail information and code helps a lot. Thanks!

ctheadn8954
  • 129
  • 1
  • 8
  • By "kill" I assume you mean that you forcefully terminated the parent process. So the normal shutdown code doesn't run. With console applications the normal signals we can get are `CTRL_C_EVENT` (Ctrl+C), `CTRL_BREAK_EVENT` (Ctrl+Break), and `CTRL_CLOSE_EVENT` (close the console window). The console can be closed via Task Manager or taskkill.exe if we non-forcefully kill the process that effectively owns the console, which is usually the process that allocated it (e.g. cmd.exe or python.exe). The main Python process needs to set a console control handler at startup via `SetConsoleCtrlHandler`. – Eryk Sun Dec 12 '18 at 21:01
  • If you need to handle the case where the main process is forcefully terminated, then you'll have to use a Job object that's set to kill on close. Ideally to avoid race conditions we'd like to add the parent process to the Job and have child processes inherit it. This can be complicated if we have to support Windows 7 and earlier since the old implementation limits a process to a single Job. – Eryk Sun Dec 12 '18 at 21:09

0 Answers0