m-labs / artiq

A leading-edge control system for quantum information experiments
https://m-labs.hk/artiq
GNU Lesser General Public License v3.0
425 stars 196 forks source link

Applet processes lingering around after browser/dashboard exit/crash #435

Open jordens opened 8 years ago

jordens commented 8 years ago
15495 ?        Ssl    0:00 /home/rj/src/conda/envs/py35/bin/python -m artiq.applets.plot_xy --embed 12,15 flopping_f_brightness
15496 ?        Ssl    0:00 /home/rj/src/conda/envs/py35/bin/python -m artiq.applets.plot_xy --embed 16,19 flopping_f_brightness
15538 ?        Ssl    0:00 /home/rj/src/conda/envs/py35/bin/python -m artiq.applets.plot_xy --embed 12,15 flopping_f_brightness
15539 ?        Ssl    0:00 /home/rj/src/conda/envs/py35/bin/python -m artiq.applets.plot_xy --embed 16,19 flopping_f_brightness
15580 ?        Ssl    0:00 /home/rj/src/conda/envs/py35/bin/python -m artiq.applets.plot_xy --embed 12,15 flopping_f_brightness
15581 ?        Ssl    0:00 /home/rj/src/conda/envs/py35/bin/python -m artiq.applets.plot_xy --embed 16,19 flopping_f_brightness

I suspect they only survive when a GUI actually crashes hard. They shoud not occur in other cases.

Can we/do we want to try to clean them up better?

whitequark commented 8 years ago

I figure the perfect solution here is to use job objects on Windows and cgroups on Linux, so that when the "root" exits, in any way whatsoever, the OS murders the rest of the processes it's grouped with. win32api from stdlib is the way to do this on Windows and cgroup-utils is the way to do this on Linux, although I'm not quite sure if the latter exposes all the knobs we need.

sbourdeauducq commented 8 years ago

An easier solution without more dependencies/components may be to make sure that applets exit immediately when the other end of their IPC pipe is closed. This assumes 1) both Windows and Linux provide a sane API for this 2) Python's asyncio didn't mess it up. Those are nontrivial assumptions.

whitequark commented 8 years ago

That doesn't handle the case where an applet is hung, and that also hangs the GUI because their message loops interlock, and the user exits the GUI process. (Although, does this actually happen with Qt window embedding? I'm pretty sure it happens with other frameworks...)

jordens commented 8 years ago

The rationale to have child processes in new sessions is here: https://github.com/m-labs/artiq/commit/fef72506e4a25e754172a885afbc05fc15530523 It still seems correct and desirable to have this behavior for ctlmgr and workers but maybe not for applets.