Skip to content

Commit

Permalink
Added NestablePool class
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiocfabini committed Jul 19, 2022
1 parent e40bb84 commit 8c31f03
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions python/NestablePool.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import multiprocessing
import multiprocessing.pool

class NoDaemonProcess(multiprocessing.Process):
@property
def daemon(self):
return False

@daemon.setter
def daemon(self, value):
pass


class NoDaemonContext(type(multiprocessing.get_context())):
Process = NoDaemonProcess

# We sub-class multiprocessing.pool.Pool instead of multiprocessing.Pool
# because the latter is only a wrapper function, not a proper class.
class NestablePool(multiprocessing.pool.Pool):
def __init__(self, *args, **kwargs):
kwargs['context'] = NoDaemonContext()
super(NestablePool, self).__init__(*args, **kwargs)

0 comments on commit 8c31f03

Please sign in to comment.