Last will and testament…

·

Here is an example code snippet that executes ‘last rites’. My current use-case is to handle final tasks on a cluster job management system when the script violates some execution criterion e.g. exceeding memory quota. It’s helpful if the job could perform some task(s) that indicate that it had to be terminated.

The key module here is the Python signal package which provides a way to handle various system signals. The example here sends an email whenever the script is terminated. To use signal you need to register one or more signals to have a handle i.e. a callback to be executed if that signal is raised. For example:

registers the handler function when the script receives an keyboard interrupt (Control-C) event.

You can view a full list of signals here.

Leave a Reply

Your email address will not be published. Required fields are marked *

Get updates

From art exploration to the latest archeological findings, all here in our weekly newsletter.

Subscribe