Python 2 multiprocessing examples in docs.python.org

Xavier Ho contact at xavierho.com
Thu Jan 31 23:14:49 EST 2013


Hey all,

I ran the example code on multiprocessing.  On the "Pool example", an
assertion failed with "testing garbage collection".

Traceback (most recent call last):
  File "test.py", line 314, in <module>
    test()
  File "test.py", line 295, in test
    assert not worker.is_alive()
AssertionError

The relevant example code reads:

    pool = multiprocessing.Pool(2)
    DELTA = 0.1
    processes = pool._pool
    ignore = pool.apply(pow3, [2])
    results = [pool.apply_async(time.sleep, [DELTA]) for i in range(100)]

    results = pool = None

    time.sleep(DELTA * 2)

    for worker in processes:
        assert not worker.is_alive()

My questions are 1) How does that GC test work, and 2) Does that mean my GC
isn't working as fast as it should have been?

The machine's Python:

xav ❖ /tmp  > python
Python 2.7.3 (v2.7.3:70274d53c1dd, Apr  9 2012, 20:52:43)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

Cheers,
Xav
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20130201/efef1d9c/attachment.html>


More information about the Python-list mailing list