Using OMERO.script (Python) I'm submitting image analysis jobs to a cluster queue. This is all working quite nicely.
Whenever an error occurs, or whenever the user (or developer) interrupts the script I would like to clean up any remaining jobs from the queue. In order to do so I've wrapped the execution of jobs in a `try:` `finally:` block. This works quite nicely. When using `bin/omero script run` the script can be cancelled using ctrl+c and the finally block is executed, and any remaining jobs are removed.
However, when sending a SIGINT (kill [pid]) to the process this block is never executed. As an alternative to `finally`: I tried this block of code. Which also does not get executed.
- Code: Select all
import signal
import sys
def signal_handler(signal, frame):
print "Got SIGINT"
signal.signal(signal.SIGINT, signal_handler)
As the SIGINT signal is also sent when the script is being cancelled from for example OMERO.insight. This also doesn't cleanup remaining cluster jobs.
What's a workable solution to this problem? Is there a way to make a shutdown handler for OMERO.script?
Thanks,
Paul