Skip to content

ConnectionResetError on Python 3.8 for windows #1023

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
erezsh opened this issue Dec 7, 2019 · 9 comments
Closed

ConnectionResetError on Python 3.8 for windows #1023

erezsh opened this issue Dec 7, 2019 · 9 comments
Labels

Comments

@erezsh
Copy link
Contributor

erezsh commented Dec 7, 2019

Using the simplest feature (prompt) fails with async exception.

After running the prompt, I kept pressing a,enter.

I'm using Windows 10, prompt_toolkit.__version__ = '2.0.10'

Python 3.8.0 (tags/v3.8.0:fa919fd, Oct 14 2019, 19:21:23) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from prompt_toolkit import prompt
>>>
>>> while 1:
...     user_input = prompt('>')
...     print(user_input)
...
>a
a
>a
a
>a
a

Unhandled exception in event loop:
  File "C:\Python38\lib\asyncio\proactor_events.py", line 768, in _loop_self_reading
    f.result()  # may raise
  File "C:\Python38\lib\asyncio\windows_events.py", line 808, in _poll
    value = callback(transferred, key, ov)
  File "C:\Python38\lib\asyncio\windows_events.py", line 457, in finish_recv
    raise ConnectionResetError(*exc.args)

Exception [WinError 995] The I/O operation has been aborted because of either a thread exit or an application request
Press ENTER to continue...
>a
a
>a
a
>a
a
>a
a

Unhandled exception in event loop:
  File "C:\Python38\lib\asyncio\proactor_events.py", line 768, in _loop_self_reading
    f.result()  # may raise
  File "C:\Python38\lib\asyncio\windows_events.py", line 808, in _poll
    value = callback(transferred, key, ov)
  File "C:\Python38\lib\asyncio\windows_events.py", line 457, in finish_recv
    raise ConnectionResetError(*exc.args)

Exception [WinError 995] The I/O operation has been aborted because of either a thread exit or an application request
Press ENTER to continue...
>a
a
>a
a
>                                                                                                                       
@erezsh
Copy link
Contributor Author

erezsh commented Dec 9, 2019

Note: This happens in both x32 and x64, but much less often in x64.

@jonathanslenders
Copy link
Member

Thanks for reporting @erezsh!

I'm not sure what's going on, and wonder whether it's maybe even a bug in asyncio...

Can you see whether this is also the case for the SelectorEventLoop?

Run the following snippet before your code:

import asyncio
import selectors

selector = selectors.SelectSelector()
loop = asyncio.SelectorEventLoop(selector)
asyncio.set_event_loop(loop)

@erezsh
Copy link
Contributor Author

erezsh commented Dec 9, 2019

That seems to cure it!

What's going on here? Is it safe to use in my code?

@jonathanslenders
Copy link
Member

Python 3.8 made the ProactorEventLoop the default on Windows. The code above tells Python to use a SelectorEventLoop instead, which is similar to Python 3.7 and before.

@vstinner: Could this be a bug in the ProactorEventLoop?

@vstinner
Copy link

vstinner commented Dec 9, 2019

I have no idea. If you think that it is a bug, write a producer and post it to bugs.python.org.

@jonathanslenders
Copy link
Member

Issue opened at bugs.python.org: https://bugs.python.org/issue39010

@drskoolie
Copy link

Getting the same error when I run ijupyter in terminal.

Unhandled exception in event loop:
  File "c:\python38\lib\asyncio\proactor_events.py", line 768, in _loop_self_reading
    f.result()  # may raise
  File "c:\python38\lib\asyncio\windows_events.py", line 808, in _poll
    value = callback(transferred, key, ov)
  File "c:\python38\lib\asyncio\windows_events.py", line 457, in finish_recv
    raise ConnectionResetError(*exc.args)

Exception [WinError 995] The I/O operation has been aborted because of either a thread exit or an application request
Press ENTER to continue...

@musm
Copy link

musm commented Dec 25, 2020

Also getting this, do we have a workaround?

nogjam added a commit to nogjam/questionary that referenced this issue Jan 25, 2021
prompt-toolkit/python-prompt-toolkit#1023

Thanks to Russell Hole for the workaround implementation example:
ctxis/cbrcli@9f8da07

Code blackening left 17 files unchanged.
nogjam added a commit to nogjam/FamilyMenu that referenced this issue Jan 25, 2021
@jonathanslenders
Copy link
Member

This was fixed in Python: python/cpython#22017
Best is to upgrade to a Python version that includes the fix, like Python 3.8.7.

Otherwise, the workaround is to make sure a SelectorEventLoop is used by asyncio. See for instance how it's done here: xonsh/xonsh#3430

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants