Skip to content

Commit

Permalink
Execution pool resuse refined
Browse files Browse the repository at this point in the history
  • Loading branch information
luav committed Jul 10, 2017
1 parent 4c1b0a5 commit e08ed48
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ ExecPool(wksnum=max(cpu_count()-1, 1), afnmask=None, memlimit=0., latency=0., na
Internal attributes:
alive - whether the execution pool is alive or terminating, bool.
Should be reseted to True on resuse after the termination.
NOTE: should be reseted to True if the execution pool is reused
after the joining or termination.
"""

execute(job, async=True):
Expand Down
14 changes: 13 additions & 1 deletion mpepool.py
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,8 @@ def __init__(self, wksnum=max(_CPUS-1, 1), afnmask=None, memlimit=0., latency=0.
Internal attributes:
alive - whether the execution pool is alive or terminating, bool.
Should be reseted to True on resuse after the termination.
NOTE: should be reseted to True if the execution pool is reused
after the joining or termination.
"""
assert (wksnum >= 1 and (afnmask is None or isinstance(afnmask, AffinityMask))
and memlimit >= 0 and latency >= 0 and (name is None or isinstance(name, str))
Expand Down Expand Up @@ -834,7 +836,17 @@ def __init__(self, wksnum=max(_CPUS-1, 1), afnmask=None, memlimit=0., latency=0.

def __enter__(self):
"""Context entrence"""
self.alive = True
# Reuse execpool if possible
if not self.alive:
if not self._workers and not self._jobs:
print('WARNING{}, the non-cleared execution pool is reused'
.format('' if not self.name else ' ' + self.name))
self._tstart = None
self.alive = True
else:
raise ValueError('Terminating dirty execution pool can not be reentered:'
' alive: {}, {} workers, {} jobs'.format(self.alive
, len(self._workers), len(self._jobs)))
return self


Expand Down

0 comments on commit e08ed48

Please sign in to comment.