Skip to content

Commit e08ed48

Browse files
committed
Execution pool resuse refined
1 parent 4c1b0a5 commit e08ed48

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,8 @@ ExecPool(wksnum=max(cpu_count()-1, 1), afnmask=None, memlimit=0., latency=0., na
276276
Internal attributes:
277277
alive - whether the execution pool is alive or terminating, bool.
278278
Should be reseted to True on resuse after the termination.
279+
NOTE: should be reseted to True if the execution pool is reused
280+
after the joining or termination.
279281
"""
280282

281283
execute(job, async=True):

mpepool.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,8 @@ def __init__(self, wksnum=max(_CPUS-1, 1), afnmask=None, memlimit=0., latency=0.
785785
Internal attributes:
786786
alive - whether the execution pool is alive or terminating, bool.
787787
Should be reseted to True on resuse after the termination.
788+
NOTE: should be reseted to True if the execution pool is reused
789+
after the joining or termination.
788790
"""
789791
assert (wksnum >= 1 and (afnmask is None or isinstance(afnmask, AffinityMask))
790792
and memlimit >= 0 and latency >= 0 and (name is None or isinstance(name, str))
@@ -834,7 +836,17 @@ def __init__(self, wksnum=max(_CPUS-1, 1), afnmask=None, memlimit=0., latency=0.
834836

835837
def __enter__(self):
836838
"""Context entrence"""
837-
self.alive = True
839+
# Reuse execpool if possible
840+
if not self.alive:
841+
if not self._workers and not self._jobs:
842+
print('WARNING{}, the non-cleared execution pool is reused'
843+
.format('' if not self.name else ' ' + self.name))
844+
self._tstart = None
845+
self.alive = True
846+
else:
847+
raise ValueError('Terminating dirty execution pool can not be reentered:'
848+
' alive: {}, {} workers, {} jobs'.format(self.alive
849+
, len(self._workers), len(self._jobs)))
838850
return self
839851

840852

0 commit comments

Comments
 (0)