File Lib/multiprocessing/pool.py changed (mode: 100644) (index ffdf42614d..ae8cec4479) |
... |
... |
def worker(inqueue, outqueue, initializer=None, initargs=(), maxtasks=None, |
128 |
128 |
util.debug("Possible encoding error while sending result: %s" % ( |
util.debug("Possible encoding error while sending result: %s" % ( |
129 |
129 |
wrapped)) |
wrapped)) |
130 |
130 |
put((job, i, (False, wrapped))) |
put((job, i, (False, wrapped))) |
|
131 |
|
|
|
132 |
|
task = job = result = func = args = kwds = None |
131 |
133 |
completed += 1 |
completed += 1 |
132 |
134 |
util.debug('worker exiting after %d tasks' % completed) |
util.debug('worker exiting after %d tasks' % completed) |
133 |
135 |
|
|
|
... |
... |
class Pool(object): |
402 |
404 |
if set_length: |
if set_length: |
403 |
405 |
util.debug('doing set_length()') |
util.debug('doing set_length()') |
404 |
406 |
set_length(i+1) |
set_length(i+1) |
|
407 |
|
finally: |
|
408 |
|
task = taskseq = job = None |
405 |
409 |
else: |
else: |
406 |
410 |
util.debug('task handler got sentinel') |
util.debug('task handler got sentinel') |
407 |
411 |
|
|
408 |
|
|
|
409 |
412 |
try: |
try: |
410 |
413 |
# tell result handler to finish when cache is empty |
# tell result handler to finish when cache is empty |
411 |
414 |
util.debug('task handler sending sentinel to result handler') |
util.debug('task handler sending sentinel to result handler') |
|
... |
... |
class Pool(object): |
445 |
448 |
cache[job]._set(i, obj) |
cache[job]._set(i, obj) |
446 |
449 |
except KeyError: |
except KeyError: |
447 |
450 |
pass |
pass |
|
451 |
|
task = job = obj = None |
448 |
452 |
|
|
449 |
453 |
while cache and thread._state != TERMINATE: |
while cache and thread._state != TERMINATE: |
450 |
454 |
try: |
try: |
|
... |
... |
class Pool(object): |
461 |
465 |
cache[job]._set(i, obj) |
cache[job]._set(i, obj) |
462 |
466 |
except KeyError: |
except KeyError: |
463 |
467 |
pass |
pass |
|
468 |
|
task = job = obj = None |
464 |
469 |
|
|
465 |
470 |
if hasattr(outqueue, '_reader'): |
if hasattr(outqueue, '_reader'): |
466 |
471 |
util.debug('ensuring that outqueue is not full') |
util.debug('ensuring that outqueue is not full') |
File Lib/test/_test_multiprocessing.py changed (mode: 100644) (index b5f4782546..1d3bb0f8ba) |
... |
... |
import random |
18 |
18 |
import logging |
import logging |
19 |
19 |
import struct |
import struct |
20 |
20 |
import operator |
import operator |
|
21 |
|
import weakref |
21 |
22 |
import test.support |
import test.support |
22 |
23 |
import test.support.script_helper |
import test.support.script_helper |
23 |
24 |
|
|
|
... |
... |
def raise_large_valuerror(wait): |
1738 |
1739 |
time.sleep(wait) |
time.sleep(wait) |
1739 |
1740 |
raise ValueError("x" * 1024**2) |
raise ValueError("x" * 1024**2) |
1740 |
1741 |
|
|
|
1742 |
|
def identity(x): |
|
1743 |
|
return x |
|
1744 |
|
|
|
1745 |
|
class CountedObject(object): |
|
1746 |
|
n_instances = 0 |
|
1747 |
|
|
|
1748 |
|
def __new__(cls): |
|
1749 |
|
cls.n_instances += 1 |
|
1750 |
|
return object.__new__(cls) |
|
1751 |
|
|
|
1752 |
|
def __del__(self): |
|
1753 |
|
type(self).n_instances -= 1 |
|
1754 |
|
|
1741 |
1755 |
class SayWhenError(ValueError): pass |
class SayWhenError(ValueError): pass |
1742 |
1756 |
|
|
1743 |
1757 |
def exception_throwing_generator(total, when): |
def exception_throwing_generator(total, when): |
|
... |
... |
def exception_throwing_generator(total, when): |
1746 |
1760 |
raise SayWhenError("Somebody said when") |
raise SayWhenError("Somebody said when") |
1747 |
1761 |
yield i |
yield i |
1748 |
1762 |
|
|
|
1763 |
|
|
1749 |
1764 |
class _TestPool(BaseTestCase): |
class _TestPool(BaseTestCase): |
1750 |
1765 |
|
|
1751 |
1766 |
@classmethod |
@classmethod |
|
... |
... |
class _TestPool(BaseTestCase): |
2000 |
2015 |
# check that we indeed waited for all jobs |
# check that we indeed waited for all jobs |
2001 |
2016 |
self.assertGreater(time.time() - t_start, 0.9) |
self.assertGreater(time.time() - t_start, 0.9) |
2002 |
2017 |
|
|
|
2018 |
|
def test_release_task_refs(self): |
|
2019 |
|
# Issue #29861: task arguments and results should not be kept |
|
2020 |
|
# alive after we are done with them. |
|
2021 |
|
objs = [CountedObject() for i in range(10)] |
|
2022 |
|
refs = [weakref.ref(o) for o in objs] |
|
2023 |
|
self.pool.map(identity, objs) |
|
2024 |
|
|
|
2025 |
|
del objs |
|
2026 |
|
self.assertEqual(set(wr() for wr in refs), {None}) |
|
2027 |
|
# With a process pool, copies of the objects are returned, check |
|
2028 |
|
# they were released too. |
|
2029 |
|
self.assertEqual(CountedObject.n_instances, 0) |
|
2030 |
|
|
2003 |
2031 |
|
|
2004 |
2032 |
def raising(): |
def raising(): |
2005 |
2033 |
raise KeyError("key") |
raise KeyError("key") |