Author vstinner
Recipients vstinner
Date 2018-12-13.01:14:15
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1544663657.8.0.788709270274.issue35479@psf.upfronthosting.co.za>
In-reply-to
Content
Attached PR 11136 modify _worker_handler() loop to wait on threading.Event events, so Pool.join() completes as soon as possible.

Example:
---
import multiprocessing
import time

def the_test():
    start_time = time.monotonic()
    pool = multiprocessing.Pool(1)
    res = pool.apply_async(int, ("1",))
    pool.close()
    #pool.terminate()
    pool.join()
    dt = time.monotonic() - start_time
    print("%.3f sec" % dt)

the_test()
---

Minimum timing with _handle_results() using:

* current code (time.sleep(0.1)): min 0.132 sec
* time.sleep(1.0): min 1.033 sec
* my PR using events (wait(0.1)): min 0.033 sec

Currently, join() minimum timing depends on _handle_results() sleep() duration (100 ms).

With my PR, it completes as soon as possible: when state change and/or when a result is set.

My PR still requires an hardcoded delay of 100 ms to workaround bpo-35478 bug: results are never set if the pool is terminated.
History
Date User Action Args
2018-12-13 01:14:17vstinnersetrecipients: + vstinner
2018-12-13 01:14:17vstinnersetmessageid: <1544663657.8.0.788709270274.issue35479@psf.upfronthosting.co.za>
2018-12-13 01:14:17vstinnerlinkissue35479 messages
2018-12-13 01:14:15vstinnercreate