Skip to content
Advertisement

GNU Parallel and Python atexit

I was trying to run a python script with GNU parallel. Everything seems to work, except for the atexit routine used inside the python script. It seems, after ctrl+c, parallel is killing the python process without giving python a chance to call the registered atexit routine. How to make parallel a bit nicer towards the child processes?

Here is an example to show the behaviour.

test_signal.py:

JavaScript

Tested with the command:

JavaScript

Advertisement

Answer

GNU Parallel kills jobs as specified in --termseq. It defaults to:

JavaScript

So SIGTERM, wait 200 ms, SIGTERM, wait 100 ms, SIGTERM, wait 50 ms, SIGKILL, wait 25 ms. If the process dies while waiting, GNU Parallel ignores the rest of the sequence – no need to kill a dead horse.

Change --termseq to the signals you want sent and the time between them.

CTRL-C sends SIGINT, so this should work:

JavaScript

Just be aware that you will not see the output unless you use --ungroup.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement