habitat.utils.crashmat: Error handling and process termination

crashmat provides a replacement for threading.Thread that, instead of printing unhandled exceptions in threads and then quietly killing it, will panic when a thread fails: it writes an error message to the log, attempts to call a graceful shutdown function, but ultimatly ensures that the process terminates (via signal.alarm()).

habitat.utils.crashmat.set_shutdown_function(f)[source]

Set a shutdown_function; see panic()

habitat.utils.crashmat.panic()[source]

panic() attempts to terminate the python process completely.

If a shutdown_function has been set via set_shutdown_function() then this function will call signal.alarm(), and then it will call the shutdown function. This has the effect that if the shutdown function fails to kill the programe cracefully, it will die anyway in 60 seconds.

Otherwise, this function will simply raise SIGKILL, causing immediate death.

class habitat.utils.crashmat.Thread(*args, **kwargs)[source]

A Thread class that kills the process in response to unhandled exceptions.

This class behaves identically to threading.Thread, with the exception that if there is an unhandled exception, panic() will be called.

handle_exception()[source]

handle_exception() is called in response to an unhandled exception

It will call logging.Logger.exception() and then panic()

Previous topic

habitat.utils.checksums: Various checksum calculation functions

Next topic

habitat.utils.dynamicloader: a generic dynamic module loader

This Page