Signals and Threads in Python 3.5 or so

Marko Rauhamaa marko at pacujo.net
Mon Oct 10 02:27:36 EDT 2016


Dan Stromberg <drsalists at gmail.com>:
> That bug is: if you control-C the top-level process, all the
> subprocesses are left running.

Sorry, don't have a solution for your particular Python situation.

> I've been thinking about making it catch SIGINT, SIGTERM and SIGHUP,
> and having it SIGKILL its active subprocesses upon receiving one of
> these signals.

SIGKILL is probably a bad idea. It doesn't give the subprocess any
opportunity for a graceful exit. For example, Python's try/finally
blocks will fail to work as advertised. Better use a catchable signal.

> However, it's multithreaded, and I've heard that in CPython, threads
> and signals don't mix well.

Python does confuse matters, but both threads and signals are
problematic entities under Linux. You need to be very well versed in the
semantics of both operating system concepts (man 7 pthreads, man 7
signal).


Marko



More information about the Python-list mailing list