简体   繁体   中英

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 .

Python有atexit -handlers,根据我的经验,这是非常可靠的。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM