-
Notifications
You must be signed in to change notification settings - Fork 72
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
asyncio support #154
Comments
This would be awesome! My shim is good enough for what I'm building, but I would love to have asyncio supported further upstream in blessed itself. Cheers. |
Since I could use asyncio support in blessed for a future project of mine, I'm willing to tackle this, provided there is still interest in including this in the library and provided I get a bit of input and help on the design decisions that follow. |
I think any help would be appreciated, though I can't guarantee how quickly we'll be able to respond to PRs. |
Hey, I've got an easy workaround for an asyncio-compatible The example script waits for a user-input in a asyncio-loop. import asyncio
import threading
from asyncio import Queue
from blessed import Terminal
queue = Queue()
term = Terminal()
def threaded_inkey():
running = True
with term.cbreak():
while running:
key = term.inkey()
if key == "q":
running = False
queue.put_nowait(key)
queue._loop._write_to_self()
async def mainloop():
running = True
with term.fullscreen():
print("press a key. (exit using 'q')")
while running:
try:
key = await asyncio.wait_for(queue.get(), 1)
if key == "q":
running = False
print("key pressed:", key)
except asyncio.TimeoutError:
print("no key pressed")
loop = asyncio.get_event_loop()
threading.Thread(target=threaded_inkey).start()
loop.run_until_complete(mainloop()) Do you want me to add a PR to add this to the documentation? Best, |
as asyncio has been considered, is there enough room for trio? --- update maybe an useful reference: starlette has supported trio via anyio --- update |
Since I've recently started playing around with trio and I like it a bit better even than asyncio, my current plan was to have a look if this is easily doable using anyio. It's on my ToDo list and since this is relevant for a project at work I'll get to it at one point for sure, but currently can't promise a timeline. |
Thank you @wagnerflo, @da-h, and @haolian9 for your initiative to add asyncio support to blessed. I'm glad to see there is some interest here. I forgot to link @haliphax's Just a reminder that for this change to be accepted it will need,
|
inkey()
, I'd like to provide an API-compatible method -- @haliphax plugged blessed and asyncssh together, so onlyinkey()
required overloading,FlowControlMixin
must be duplicated downstream? https://bugs.python.org/issue34993Maybe we can be of help, here.
Propose:
asyncio=True
in the class constructor, swaps out anyinkey()
and similar methods withawait_inkey()
and other asyncio definitions at instantiation time, when initializedTerminal(asyncio=True)
.inkey()
and others function as documented without asyncio, or, with asyncio, to function with the same behavior and signature, but to use expressionawait Terminal.inkey()
withasyncio=True
argument to class constructor.The text was updated successfully, but these errors were encountered: