Kyle Stanley <aeros...@gmail.com> added the comment:

As of now, I have the implementation for ThreadPoolExecutor working correctly, 
and a unit test added to ensure its behavior. It was a bit more involved than I 
originally anticipated, as I had to make a minor change in the _worker() 
function to allow the new parameter to be compatible with wait (which is 
important, as it prevents dangling threads).

With my initial implementation, using "wait=True" and "cancel_futures=True" was 
resulting in any threads that called work_queue.get(block=True) to hang 
indefinitely. In order to remedy this, I changed it to use 
work_queue.get_nowait(). If a queue.Empty exception occurs, it checks for a 
global constant _cancelling_futures (set to True just in shutdown before it 
starts draining the work queue). If it's true, the while True loop is broken, 
otherwise it continues to the next iteration. This effectively has the same 
behavior as before. 

I experimented with a few different possible solutions, and the above was the 
only one that worked while still maintaining the current behavior as much as 
possible. From what I can tell, this was the only viable means of implementing 
the new parameter without making it entirely incompatible with "wait=True".

At this point, I believe the only remaining step for the ThreadPoolExecutor 
implementation is to update the documentation and decide on the name. After 
working with it, I'm leaning more towards *cancel_futures*, as I think this 
more accurately describes what it does compared to just *cancel* (which is a 
bit vague IMO).

----------
title: Add "cancel" parameter to concurrent.futures.Executor.shutdown() -> Add 
"cancel_futures" parameter to concurrent.futures.Executor.shutdown()

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue39349>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to