0

In an answer to the question "Python Process Pool non-daemonic?" it is shown how to disable the daemon attribute of a process:

class NoDaemonProcess(multiprocessing.Process):
    # make 'daemon' attribute always return False
    def _get_daemon(self):
        return False
    def _set_daemon(self, value):
        pass
    daemon = property(_get_daemon, _set_daemon)

# We sub-class multiprocessing.pool.Pool instead of multiprocessing.Pool
# because the latter is only a wrapper function, not a proper class.
class MyPool(multiprocessing.pool.Pool):
    Process = NoDaemonProcess

This allows for a process in a pool to start it's own child process, as explained in the original question.

In exchange for the flexibility of starting child processes, what costs is paid? If there were no costs, presumably the standard Pool would have used non-daemonic processes.

Note: this question is based on a highly upvoted comment that went unaddressed, so I decided to convert it to a question.

Seanny123
  • 8,776
  • 13
  • 68
  • 124

1 Answers1

1

A daemonic process will be killed if its parent process terminates. A non-daemonic process will block its parent process from terminating until it terminates too.

So if you don't mind sub-processes blocking its parent process, you can feel free to use non-daemonic process.

Sraw
  • 18,892
  • 11
  • 54
  • 87