Author mrqianjinsi
Recipients mrqianjinsi
Date 2019-06-12.08:35:31
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
Hi guys.
I'm using multiprocessing module to accelerate my program. and I want to do some cleanup work when sub-process exit. 
but I found that sub-process would be terminated when registered finalizer are working.

Is this behavior designed intentionally?

code example:

import multiprocessing as mp
from multiprocessing.util import Finalize
import os
import time

def finalizer():
    time.sleep(0.2) # some time consuming work
    print('do cleanup work: {}'.format(os.getpid()))

def worker(_):
    print('do some work: {}'.format(os.getpid()))

def initializer():
    # ref:
    Finalize(None, finalizer, exitpriority=1)

    # atexit module don't work along with multiprocessing module
    # because sub-process exit via os._exit()
    # ref:
    # atexit.register(finalizer)  # don't work

print('main process ID: {}'.format(os.getpid()))
with mp.Pool(4, initializer=initializer) as executor:, range(20))

gist link:
Date User Action Args
2019-06-12 08:35:31mrqianjinsisetrecipients: + mrqianjinsi
2019-06-12 08:35:31mrqianjinsisetmessageid: <>
2019-06-12 08:35:31mrqianjinsilinkissue37242 messages
2019-06-12 08:35:31mrqianjinsicreate