prompt-toolkit / prompt-toolkit/python-prompt-toolkit

How to answer a prompt from a different thread / task?

Open
#1,914 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
10.6k
Forks
815
PR merge metrics
No merged PRs in 30d

Description

Hello and thanks for this cool library!

Given this example

from prompt_toolkit import prompt

def main():
    text = prompt('> ')
    print('You entered:', text)

if __name__ == '__main__':
    main()

How would I answer the prompt programmatically from a different thread or asyncio task?
I digged up a bit and it looks like under the hood prompt calls asyncio.run(coro) where coro is an internal coroutine that reacts to key pressure in the terminal.

There is a way to get that coroutine and maybe stop it or change its status?
Or maybe some trick to fake keyboard pressure?

Thanks!

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the prompt entry point and the internal coroutine described in the issue, including its use of asyncio.run(coro). Investigate whether an existing API supports input from another thread or asyncio task, or whether the requested behavior needs a new interface; done means a documented, reproducible way to provide that input programmatically.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.