Skip to content

Don't nest asyncio input hooks. - #12001

Merged
Carreau merged 2 commits into
ipython:masterfrom
jonathanslenders:asyncio-inputhook-fix
Dec 4, 2019
Merged

Carreau merged 2 commits into
ipython:masterfrom
jonathanslenders:asyncio-inputhook-fix

Conversation

@jonathanslenders

Copy link
Copy Markdown
Contributor

This fixes the "event loop already running" error.

For prompt_toolkit 2.0: this will still nest the event loops, but that's fine,
because we have the asyncio event loop running an prompt_toolkit's custom loop.
They don't interfere with each other.

For prompt_toolkit 3.0: we only use one asyncio event loop when "%gui asyncio"
is used. The terminal prompt will now use the active asyncio event loop.

This fixes the "event loop already running" error.

For prompt_toolkit 2.0: this will still nest the event loops, but that's fine,
because we have the asyncio event loop running an prompt_toolkit's custom loop.
They don't interfere with each other.

For prompt_toolkit 3.0: we only use one asyncio event loop when "%gui asyncio"
is used. The terminal prompt will now use the active asyncio event loop.
import asyncio
from prompt_toolkit import __version__ as ptk_version

PTK3 = ptk_version.startswith('3.')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will result in incorrect logic when pt4 comes out. Let's parse it out correctly:

Suggested change
PTK3 = ptk_version.startswith('3.')
PTK3 = int(ptk_version.split('.', 1)[0]) >= 3

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My guess is PTK4 will also have a different API; so wether we go through the PTK2 or PTK3 branch it will fail.

It's also the same check we have in other locations... But up to @jonathanslenders

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really have any opinion. In setup.py, we explicitly mention to not install PTK4, and at the point where we upgrade, it's easy enough to fix this to whatever makes sense.

@Carreau Carreau added this to the 7.10.2 milestone Dec 4, 2019
@Carreau

Carreau commented Dec 4, 2019

Copy link
Copy Markdown
Member

Should that go in a 7.11 or a 7.10.2 ?

@jonathanslenders

Copy link
Copy Markdown
Contributor Author

@Carreau : I consider it a bugfix, not sure in what version it should be merged.

@Carreau

Carreau commented Dec 4, 2019

Copy link
Copy Markdown
Member

Ok, let's get that in, I'll try to do a patch release soon.

@Carreau
Carreau merged commit 8e34b1a into ipython:master Dec 4, 2019
meeseeksmachine pushed a commit to meeseeksmachine/ipython that referenced this pull request Dec 4, 2019
Carreau added a commit that referenced this pull request Dec 4, 2019
…001-on-7.10.x

Backport PR #12001 on branch 7.10.x (Don't nest asyncio input hooks.)
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.

3 participants