-
-
Notifications
You must be signed in to change notification settings - Fork 178
Implement async input() #213
Comments
You can use loop.add_reader(fd, cb) and add a callback function to stdin file descriptor and change tty settings to cbreak. Or you can make a coroutine to read from curses screen getch method with nodelay option. I'm sure there is a more robust/complicated way to this, maybe including StreamReader. |
I implemented something similar as part of this project. It provides the following coroutines:
Everything is implemented in stream.py. It should work even if |
https://gist.github.com/nathan-hoad/8966377 - is it good ? @vxgmichel |
I'm vote on implementing stream wrappers for generic file objects. Something like simple and stupid
|
@socketpair There are a few differences between the example in your link and the way I wrote it:
About the wrappers you described, I'm not sure it's a good idea to create high level streams from low level objects (file objets, descriptors, sockets). For instance, in order to open a new socket connection, you can either use:
Same thing for subprocesses:
So I would expect file streams to work the same:
|
@vxgmichel unfortunatelly, there are cases where file descriptor is pre-exist. For example, systemd's socket activation, or xinetd. Also, if stdout/stdin is pipe, input and output may block easily, so wrapping them to asyncio stream is convenient. |
FWIW an issue with my gist is that it will break print() calls for sufficiently large output, because stdout is... surprise surprise, non-blocking. Even if you decide to only have a non-blocking stdin you'll hit issues, because stdin and stdout are actually the same object for TTYs, as per this issue: #147. Also, |
Original issue reported on code.google.com by
[email protected]
on 2 Nov 2014 at 10:55The text was updated successfully, but these errors were encountered: