Skip to content

Commit 9a0d050

Browse files
committed
Fix "AssertionError: group argument must be None for now" errors
Some Python versions replacing the standard Pool with our custom Pool causes the following error: "AssertionError: group argument must be None for now." [1] This change uses a different approach, solving this issue. [1]: nipy/nipype#2754
1 parent fc301aa commit 9a0d050

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

deepaas/model/v2/wrapper.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -325,19 +325,24 @@ def get_predict_args(self):
325325
return {}
326326

327327

328-
class NoDaemonProcess(multiprocessing.Process):
329-
# make 'daemon' attribute always return False
330-
def _get_daemon(self):
331-
return False
328+
class NonDaemonPool(multiprocessing.pool.Pool):
329+
def Process(self, *args, **kwds):
330+
proc = super(NonDaemonPool, self).Process(*args, **kwds)
332331

333-
def _set_daemon(self, value):
334-
pass
332+
class NonDaemonProcess(proc.__class__):
333+
"""Monkey-patch process to ensure it is never daemonized"""
335334

336-
daemon = property(_get_daemon, _set_daemon)
335+
@property
336+
def daemon(self):
337+
return False
337338

339+
@daemon.setter
340+
def daemon(self, val):
341+
pass
338342

339-
class Pool(multiprocessing.pool.Pool):
340-
Process = NoDaemonProcess
343+
proc.__class__ = NonDaemonProcess
344+
345+
return proc
341346

342347

343348
class CancellablePool(object):
@@ -347,7 +352,7 @@ def __init__(self, max_workers=None):
347352
self._change = asyncio.Event()
348353

349354
def _new_pool(self):
350-
return Pool(1)
355+
return NonDaemonPool(1)
351356

352357
async def apply(self, fn, *args):
353358
"""

0 commit comments

Comments
 (0)