Register multiple excepthooks?

Dieter Maurer dieter at handshake.de
Mon Aug 1 13:34:49 EDT 2022


Albert-Jan Roskam wrote at 2022-7-31 11:39 +0200:
>   I have a function init_logging.log_uncaught_errors() that I use for
>   sys.excepthook. Now I also want to call another function (ffi.dlclose())
>   upon abnormal termination. Is it possible to register multiple
>   excepthooks, like with atexit.register? Or should I rename/redefine
>   log_uncaught_errors() so it does both things?

`sys.excepthook` is a single function (not a list of them).
This means: at any moment a single `excepthook` is effective.

If you need a modular design, use a dispatcher function
as your `excepthook` associated with a registry (e.g. a `list`).
The dispatcher can then call all registered function.


More information about the Python-list mailing list