prompt-toolkit / prompt-toolkit/python-prompt-toolkit
asyncio prompt example hangs
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 10.6k
- Forks
- 815
- PR merge metrics
- No merged PRs in 30d
Description
The following example, taken straight from the documentation (with the first and last line added) hangs for me using Python 3.7.2. I have to kill the process to escape:
import asyncio
from prompt_toolkit import prompt
from prompt_toolkit.eventloop.defaults import use_asyncio_event_loop
from prompt_toolkit.patch_stdout import patch_stdout
# Tell prompt_toolkit to use the asyncio event loop.
use_asyncio_event_loop()
async def my_coroutine():
while True:
with patch_stdout():
result = await prompt('Say something: ', async_=True)
print('You said: %s' % result)
asyncio.run(my_coroutine())
Can anyone suggest a version that works? I am hoping to make a really simple command-line GUI that uses asyncio and takes input in one panel and prints output in another, but this is a show stopper.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the documentation example under Python 3.7.2, focusing on the asyncio event-loop setup, patch_stdout context, and async prompt call shown in the issue. Compare the documented example with a working asyncio prompt flow; done means the loop accepts input and prints each response without hanging.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100