1

When using Python multiprocessing, what is the proper way to ensure code will run to cleanup whenever a process exits (both cleanly or on fatal error.)

If I am writing my processes as inheriting from the Process object, should I put this functionality in the __del__ method of the object? I tried putting simple log statements into terminate, but it doesn't seem to execute when the script receives a SIGHUP or KeyboardInterrupt.

1 Answer 1

1

Python has atexit-handlers, which are pretty reliable in my experience.

Sign up to request clarification or add additional context in comments.

2 Comments

Yeah -- IIRC, atexit doesn't handle signals though.
@senderie: you are right. signals not handled by python, will bypass the atexit-handler. I guess it is possible to write signal-handlers for those cases. The docs have all the smallprint.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.