Search code examples
pythonmultiprocessingpool

prevent AssertionError: daemonic processes are not allowed to have children


I am running stuff using Pool/multiprocessing. Whenever I call Pool again (nested) within one of the child processes of the main process, this error is raised?

prevent multiprocessing gives AssertionError: daemonic processes are not allowed to have children

Is there a way to detect if code is running already part of a Pool, to be able to prevent this error?


Solution

  • Yes, you can get the current process instance and check whether it is daemonic or not:

    from multiprocessing import process
    
    print(f"is current process daemonic: {process.current_process().daemon}")
    

    Output:

    is current process daemonic: False
    

    Inside a pool, that .daemon property will be True