New submission from Mark Nemec <mark.ne...@gmail.com>:

Currently, one can submit a task to an executor (both ThreadPoolExecutor and 
ProcessPoolExecutor) during interpreter shutdown. One way to do this is to 
register function fun with atexit as below.

@atexit.register
def fun():
   pool.submit(print, "apple")

The future is accepted and goes into PENDING state. However, this can cause 
issues if the _python_exit function (located in concurrent/futures/thread.py 
and/or concurrent/futures/process.py) executes before function fun.

Function _python_exit will shutdown the running workers in the pool and hence 
there will be no workers running by the time fun is executed so the future will 
be left in PENDING state forever.

The solution submitted here is to instead raise a RuntimeException when a task 
is submitted during interpreter shutdown. This is the same behaviour as when 
the shutdown method of an executor is called explicitly.

----------
components: Library (Lib)
messages: 314044
nosy: Mark Nemec
priority: normal
severity: normal
status: open
title: concurrent.futures executors accept tasks after interpreter shutdown
type: behavior
versions: Python 3.6

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

Reply via email to