Skip to content

Conversation

@nogjam
Copy link

@nogjam nogjam commented Jan 25, 2021

BEFORE FIX:

(env) C:\...\questionary>python examples/readme.py
? What's your first name Nath
? What's your secret? ****
? Are you amazed? Yes

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...
? What do you want to do? Make a reservation
? What do you want to do? Order a pizza

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...
? Select toppings [bazz]
? Path to the projects version file questionary\__init__.py

(env) C:\...\questionary> 

AFTER FIX:

(env) C:\...\questionary>python examples/readme.py
? What's your first name Nath
? What's your secret? ****
? Are you amazed? Yes
? What do you want to do? Make a reservation
? What do you want to do? Order a pizza
? Select toppings [bazz]
? Path to the projects version file questionary\__init__.py

(env) C:\...\questionary>

Open issue (as of Jan. 24, 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.

prompt-toolkit/python-prompt-toolkit#1023

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

Code blackening left 17 files unchanged.
@kiancross
Copy link
Collaborator

Thanks for the PR - are there any side effects to this? Does it need reverting when fixed upstream?

@nogjam
Copy link
Author

nogjam commented Feb 1, 2021

@kiancross Sorry, I'm fairly new at using PRs. Could you please elaborate or point me to something I can read to get up to speed?

What is upstream? How do I make/test a fix upstream? What do you mean does it need reverting - are you asking whether this fix will not work further upstream? And how will I know whether there are any side effects?

@kiancross
Copy link
Collaborator

Hi @n8jhj :)

You referenced prompt-toolkit/python-prompt-toolkit#1023, which in turn referenced this bug. So it looks like there is a problem with Python (which is what I mean by 'upstream'). I was asking whether this fix needs reverting once the upstream issue (i.e. the Python issue) is fixed (i.e. is this fix temporary?).

The workaround you have given uses a SelectorEventLoop instead of a ProactorEventLoop - I am unfamiliar with the differences, so I was wondering if there would be any (negative) side effects to this change? E.g. could/would this cause problems for Unix users?

If you don't know the answers, don't worry - I can check myself when I have time :)


Does adding your fix before importing questionary also fix the issue?

@nogjam
Copy link
Author

nogjam commented Feb 1, 2021

@kiancross Ah! Beautiful, thanks for clarifying. Looks like the necessary change has been merged to cpython master and backported to Python 3.8 and 3.9: python/cpython#22066
Since questionary requires python = "^3.6", I suppose you're stuck with this bugfix until you require at least 3.8.

Looks like Python made the ProactorEventLoop the default for Windows (yet, it apparently wasn't ready for production on Windows). Something to do with Windows only supporting sockets, not pipes: https://docs.python.org/3.6/library/asyncio-eventloops.html#available-event-loops
So I don't imagine there'd be any problems for Unix-based operating systems, since the SelectorEventLoop was designed for them.


Yes, adding before questionary import still fixes it. In examples/readme.py:

# Asyncio bug workaround
# https://github.com/prompt-toolkit/python-prompt-toolkit/issues/1023
import asyncio
import selectors

selector = selectors.SelectSelector()
loop = asyncio.SelectorEventLoop(selector)
asyncio.set_event_loop(loop)
# End workaround

import questionary
from examples import custom_style_dope

if __name__ == "__main__":
    ...

Confirmed that it breaks again when removing the workaround.

@kiancross
Copy link
Collaborator

I believe that the fix has been released in Python 3.8.7 and Python 3.9.1 (ctrl + f for bpo-39010).

The change to make ProactorEventLoop the default apparently only happened in Python 3.8, which is why it has not been back-ported any further.

Can you check if this is fixed in the latest version of Python 3.8 or 3.9?

@kiancross
Copy link
Collaborator

I believe this has been patched and backported in the latest Python versions so will close this PR :) If it's still an issue, just post back on this PR and we can reopen.

@kiancross kiancross closed this May 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants