Skip to content

Runner errors for Python 3.7 when done #156

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
basnijholt opened this issue Mar 13, 2019 · 4 comments
Closed

Runner errors for Python 3.7 when done #156

basnijholt opened this issue Mar 13, 2019 · 4 comments

Comments

@basnijholt
Copy link
Member

Exception in thread QueueManagerThread:
Traceback (most recent call last):
  File "/opt/conda/lib/python3.7/threading.py", line 917, in _bootstrap_inner
    self.run()
  File "/opt/conda/lib/python3.7/threading.py", line 865, in run
    self._target(*self._args, **self._kwargs)
  File "/opt/conda/lib/python3.7/concurrent/futures/process.py", line 368, in _queue_management_worker
    thread_wakeup.clear()
  File "/opt/conda/lib/python3.7/concurrent/futures/process.py", line 92, in clear
    while self._reader.poll():
  File "/opt/conda/lib/python3.7/multiprocessing/connection.py", line 255, in poll
    self._check_closed()
  File "/opt/conda/lib/python3.7/multiprocessing/connection.py", line 136, in _check_closed
    raise OSError("handle is closed")
OSError: handle is closed
@basnijholt
Copy link
Member Author

basnijholt commented Mar 13, 2019

Might actually be a bug in Python 3.7: https://bugs.python.org/issue34073
Related: https://bugs.python.org/issue34075

However, it's not exactly the same

# Bug occurs in this way
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)
print(loop.run_until_complete(future))
loop.close()
# We're calling it like this with no error printed
import asyncio
from concurrent.futures import ProcessPoolExecutor
import os
loop = asyncio.get_event_loop_policy().new_event_loop()
ex = ProcessPoolExecutor()
future = loop.run_in_executor(ex, os.getpid)
print(loop.run_until_complete(future))
loop.close()

@basnijholt
Copy link
Member Author

basnijholt commented Mar 13, 2019

The following code is causing the bug:

import random
import concurrent.futures
import asyncio

executor = concurrent.futures.ProcessPoolExecutor()
ioloop = asyncio.get_event_loop()

async def _run():
    result = await ioloop.run_in_executor(executor, random.random)
    executor.shutdown(wait=False)  # if `wait=True` the problem is gone

task = ioloop.create_task(_run())

@basnijholt
Copy link
Member Author

I've opened an issue in the Python bug tracker: https://bugs.python.org/issue36281

basnijholt added a commit that referenced this issue Mar 18, 2019
See #156
This prevent the 'OSError: handle is closed' after the runner
is closed in Python 3.7
basnijholt added a commit that referenced this issue Mar 18, 2019
See #156
This prevent the 'OSError: handle is closed' after the runner
is closed in Python 3.7
basnijholt added a commit that referenced this issue Mar 21, 2019
See #156
This prevent the 'OSError: handle is closed' after the runner
is closed in Python 3.7
basnijholt added a commit that referenced this issue Mar 21, 2019
See #156
This prevent the 'OSError: handle is closed' after the runner
is closed in Python 3.7
basnijholt added a commit that referenced this issue Mar 21, 2019
See #156
This prevent the 'OSError: handle is closed' after the runner
is closed in Python 3.7
@basnijholt
Copy link
Member Author

Closed by #164.

This should be changed back in the future, see #173.

basnijholt added a commit that referenced this issue May 8, 2019
See #156
This prevent the 'OSError: handle is closed' after the runner
is closed in Python 3.7
@basnijholt basnijholt mentioned this issue Apr 10, 2020
6 tasks
basnijholt added a commit that referenced this issue Apr 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant