- bugfix for argument bar=False
This commit is contained in:
@@ -396,8 +396,8 @@ class PoolSingleton:
|
|||||||
def __getstate__(self):
|
def __getstate__(self):
|
||||||
raise RuntimeError(f'Cannot pickle {self.__class__.__name__} object.')
|
raise RuntimeError(f'Cannot pickle {self.__class__.__name__} object.')
|
||||||
|
|
||||||
def __del__(self):
|
# def __del__(self):
|
||||||
self.close()
|
# self.close()
|
||||||
|
|
||||||
def remove_pool(self, pool_id):
|
def remove_pool(self, pool_id):
|
||||||
self.shared_memory.remove_pool(pool_id)
|
self.shared_memory.remove_pool(pool_id)
|
||||||
@@ -491,6 +491,8 @@ class PoolSingleton:
|
|||||||
|
|
||||||
class Worker:
|
class Worker:
|
||||||
""" Manages executing the target function which will be executed in different processes. """
|
""" Manages executing the target function which will be executed in different processes. """
|
||||||
|
nested = False
|
||||||
|
|
||||||
def __init__(self, shared_memory: SharedMemory, queue_in, queue_out, n_workers, event):
|
def __init__(self, shared_memory: SharedMemory, queue_in, queue_out, n_workers, event):
|
||||||
self.shared_memory = shared_memory
|
self.shared_memory = shared_memory
|
||||||
self.queue_in = queue_in
|
self.queue_in = queue_in
|
||||||
@@ -507,6 +509,7 @@ class Worker:
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
def __call__(self):
|
def __call__(self):
|
||||||
|
Worker.nested = True
|
||||||
pid = getpid()
|
pid = getpid()
|
||||||
last_active_time = time()
|
last_active_time = time()
|
||||||
while not self.event.is_set() and time() - last_active_time < 600:
|
while not self.event.is_set() and time() - last_active_time < 600:
|
||||||
@@ -626,7 +629,7 @@ def pmap(fun, iterable=None, args=None, kwargs=None, total=None, desc=None, bar=
|
|||||||
bar_kwargs['desc'] = desc
|
bar_kwargs['desc'] = desc
|
||||||
if 'disable' not in bar_kwargs:
|
if 'disable' not in bar_kwargs:
|
||||||
bar_kwargs['disable'] = not bar
|
bar_kwargs['disable'] = not bar
|
||||||
if serial is True or (serial is None and len(iterable) < min(cpu_count, 4)): # serial case
|
if serial is True or (serial is None and len(iterable) < min(cpu_count, 4)) or Worker.nested: # serial case
|
||||||
if callable(bar):
|
if callable(bar):
|
||||||
return sum([chunk_fun(c, *args, **kwargs) for c in ExternalBar(iterable, bar)], [])
|
return sum([chunk_fun(c, *args, **kwargs) for c in ExternalBar(iterable, bar)], [])
|
||||||
else:
|
else:
|
||||||
@@ -635,7 +638,7 @@ def pmap(fun, iterable=None, args=None, kwargs=None, total=None, desc=None, bar=
|
|||||||
with ExitStack() as stack:
|
with ExitStack() as stack:
|
||||||
if callable(bar):
|
if callable(bar):
|
||||||
bar = stack.enter_context(ExternalBar(callback=bar)) # noqa
|
bar = stack.enter_context(ExternalBar(callback=bar)) # noqa
|
||||||
elif bar is True:
|
else:
|
||||||
bar = stack.enter_context(tqdm(**bar_kwargs)) # noqa
|
bar = stack.enter_context(tqdm(**bar_kwargs)) # noqa
|
||||||
with ParPool(chunk_fun, args, kwargs, bar) as p:
|
with ParPool(chunk_fun, args, kwargs, bar) as p:
|
||||||
for i, (j, l) in enumerate(zip(iterable, iterable.lengths)): # add work to the queue
|
for i, (j, l) in enumerate(zip(iterable, iterable.lengths)): # add work to the queue
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[tool.poetry]
|
[tool.poetry]
|
||||||
name = "parfor"
|
name = "parfor"
|
||||||
version = "2024.1.25"
|
version = "2024.2.0"
|
||||||
description = "A package to mimic the use of parfor as done in Matlab."
|
description = "A package to mimic the use of parfor as done in Matlab."
|
||||||
authors = ["Wim Pomp <wimpomp@gmail.com>"]
|
authors = ["Wim Pomp <wimpomp@gmail.com>"]
|
||||||
license = "GPLv3"
|
license = "GPLv3"
|
||||||
|
|||||||
Reference in New Issue
Block a user