[New-bugs-announce] [issue40093] ThreadPoolExecutor with wait=True shuts down too early

fireattack report at bugs.python.org
Fri Mar 27 19:21:42 EDT 2020


New submission from fireattack <human.peng at gmail.com>:

Example

```
from concurrent.futures import ThreadPoolExecutor
from time import sleep

def wait_on_future():
    sleep(1)
    print(f.done()) # f is not done obviously
    f2 = executor.submit(pow, 5, 2)
    print(f2.result())
    sleep(1)    
    

executor = ThreadPoolExecutor(max_workers=100)
f = executor.submit(wait_on_future)
executor.shutdown(wait=True)
```

When debugging, it shows "cannot schedule new futures after shutdown":

    Exception has occurred: RuntimeError
    cannot schedule new futures after shutdown
    File "test2.py", line 7, in wait_on_future
        f2 = executor.submit(pow, 5, 2)

According to https://docs.python.org/3/library/concurrent.futures.html, `shutdown(wait=True)` "[s]ignal the executor that it should free any resources that it is using when the currently pending futures are done executing". But when f2 is being submitted, f is not done yet, so executor shouldn't be shut down.

----------
components: Library (Lib)
messages: 365194
nosy: fireattack
priority: normal
severity: normal
status: open
title: ThreadPoolExecutor with wait=True shuts down too early
versions: Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue40093>
_______________________________________


More information about the New-bugs-announce mailing list