- add PoolSingleton to __init__

- update readme
This commit is contained in:
Wim Pomp
2024-10-20 13:10:49 +02:00
parent 57b3fbe2b2
commit d6afbc3caf
3 changed files with 27 additions and 19 deletions

View File

@@ -19,23 +19,18 @@ Result = TypeVar('Result')
Iteration = TypeVar('Iteration')
def select():
return nogil if hasattr(sys, '_is_gil_enabled') and not sys._is_gil_enabled() else gil # noqa
class ParPool:
def __new__(cls, *args, **kwargs):
try:
if not sys._is_gil_enabled(): # noqa
return nogil.ParPool(*args, **kwargs)
except AttributeError:
pass
return gil.ParPool(*args, **kwargs)
return select().ParPool(*args, **kwargs)
def nested():
try:
if not sys._is_gil_enabled(): # noqa
return nogil.Worker.nested
except AttributeError:
pass
return gil.Worker.nested
class PoolSingleton:
def __new__(cls, *args, **kwargs):
return select().PoolSingleton(*args, **kwargs)
class Chunks(Iterable):
@@ -222,7 +217,7 @@ def gmap(fun: Callable[[Iteration, Any, ...], Result], iterable: Iterable[Iterat
bar_kwargs['desc'] = desc
if 'disable' not in bar_kwargs:
bar_kwargs['disable'] = not bar
if serial is True or (serial is None and len(iterable) < min(cpu_count, 4)) or nested(): # serial case
if serial is True or (serial is None and len(iterable) < min(cpu_count, 4)) or select().Worker.nested: # serial case
def tqdm_chunks(chunks: Chunks, *args, **kwargs) -> Iterable[Iteration]: # noqa
with tqdm(*args, **kwargs) as b: