[Python-ideas] atexit.register_w_signals()

Ethan Furman ethan at stoneleaf.us
Fri Feb 12 13:46:13 EST 2016


On 02/12/2016 10:36 AM, Giampaolo Rodola' wrote:

> So, one problem with atexit.register() is that it won't run the
> registered function in case the process is killed by a signal.

[...]

> The correct way to do that is to use signal.signal(). The problem with
> that though is that in case a third-party module has
> already registered a function for that signal, the new function will
> overwrite the old one:

[...]

> I also noticed that every time I end up working on a new code base, most
> of the time people are using either atexit or signal module without
> knowing these implications. It also took quite a bit to do the same and
> come up with this code.
>
> Code:
> https://gist.github.com/giampaolo/6f07f6cd7dd1c667b0bb
>
> Relevant blog post:
> http://grodola.blogspot.com/2016/02/how-to-always-execute-exit-functions-in-py.html

The idea seems sound.  Have you considered releasing your code as a pypi 
package?

--
~Ethan~


More information about the Python-ideas mailing list