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.

Title: asyncio and ProcessPoolExecutor: OSError on loop.close()
Type: behavior Stage: resolved
Components: asyncio, Library (Lib) Versions: Python 3.8, Python 3.7
Status: closed Resolution: remind
Dependencies: Superseder:
Assigned To: Nosy List: asvetlov, jonafato, mdk, yselivanov
Priority: normal Keywords:

Created on 2018-07-09 01:30 by jonafato, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (3)
msg321297 - (view) Author: Jon Banafato (jonafato) Date: 2018-07-09 01:30
Calling loop.close() on an eventloop configured to use a ProcessPoolExecutor can result in an OSError.

Expected behavior: no exception raised.
Actual behavior: an OSError is raised, and following this call, quit() fails to terminate the process gracefully. 


Python 3.8.0a0 (default, Jul  7 2018, 14:35:49)
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import asyncio
>>> from concurrent.futures import ProcessPoolExecutor
>>> import os
>>> loop = asyncio.get_event_loop_policy().new_event_loop()
>>> loop.set_default_executor(ProcessPoolExecutor())
>>> future = loop.run_in_executor(None, os.getpid)
>>> loop.run_until_complete(future)
>>> loop.close()
Exception ignored in: <function ProcessPoolExecutor._start_queue_management_thread.<locals>.weakref_cb at 0x7f52e7f643f0>
Traceback (most recent call last):
  File "/code/Lib/concurrent/futures/", line 567, in weakref_cb
  File "/code/Lib/concurrent/futures/", line 89, in wakeup
  File "/code/Lib/multiprocessing/", line 183, in send_bytes
  File "/code/Lib/multiprocessing/", line 136, in _check_closed
Exception in thread QueueManagerThread:
Traceback (most recent call last):
  File "/code/Lib/", line 917, in _bootstrap_inner
  File "/code/Lib/", line 865, in run
    self._target(*self._args, **self._kwargs)
  File "/code/Lib/concurrent/futures/", line 368, in _queue_management_worker
  File "/code/Lib/concurrent/futures/", line 92, in clear
    while self._reader.poll():
  File "/code/Lib/multiprocessing/", line 255, in poll
  File "/code/Lib/multiprocessing/", line 136, in _check_closed
    raise OSError("handle is closed")
OSError: handle is closed

    raise OSError("handle is closed")
OSError: handle is closed
msg321299 - (view) Author: Julien Palard (mdk) * (Python committer) Date: 2018-07-09 05:36
Can reproduce with 3.7.0 on Linux.
msg321332 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2018-07-09 16:17
We plan to deprecate and later prohibit setting ProcessPoolExecutor as the default executor.  See for more details.
Date User Action Args
2022-04-11 14:59:02adminsetgithub: 78254
2018-07-09 16:17:25yselivanovsetstatus: open -> closed
resolution: remind
messages: + msg321332

stage: resolved
2018-07-09 05:36:55mdksetnosy: + mdk
messages: + msg321299
2018-07-09 01:30:20jonafatocreate