This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author miles
Recipients miles
Date 2015-02-03.08:20:02
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1422951603.17.0.63584283635.issue23382@psf.upfronthosting.co.za>
In-reply-to
Content
Maybe can not shutdown ThreadPoolExecutor when call the method shutdown.

Though the variable of _shutdown is set to true in the method of shutdown, it may also reads the variable of _shutdown from cpu cache in the method of _worker, and the worst case is that it could see an out-of-date value of _shutdown forever. so need to acquire lock before reading the variable of _shutdown to make sure see an up-to-date value.


the following is the new code:



def _worker(executor_reference, work_queue):
    try:
        while True:
            work_item = work_queue.get(block=True)
            if work_item is not None:
                work_item.run()
                continue
            executor = executor_reference()
            
            shutdown = False
            with executor._shutdown_lock.acquire():
                shutdown = executor._shutdown
            
            # Exit if:
            #   - The interpreter is shutting down OR
            #   - The executor that owns the worker has been collected OR
            #   - The executor that owns the worker has been shutdown.
            if _shutdown or executor is None or shutdown:
                # Notice other workers
                work_queue.put(None)
                return
            del executor
    except BaseException:
        _base.LOGGER.critical('Exception in worker', exc_info=True)




    def shutdown(self, wait=True):
        with self._shutdown_lock:
            self._shutdown = True
            self._work_queue.put(None)
        if wait:
            for t in self._threads:
                t.join()
History
Date User Action Args
2015-02-03 08:20:03milessetrecipients: + miles
2015-02-03 08:20:03milessetmessageid: <1422951603.17.0.63584283635.issue23382@psf.upfronthosting.co.za>
2015-02-03 08:20:03mileslinkissue23382 messages
2015-02-03 08:20:02milescreate