Mark Grey
Mark Grey

Reputation: 10257

python multiprocessing - run logic when process terminates

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.

Upvotes: 1

Views: 260

Answers (1)

mirk
mirk

Reputation: 5510

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

Upvotes: 1

Related Questions