Skip to content
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

Opening/Reading character device #1395

Closed
joernheissler opened this issue Feb 9, 2020 · 4 comments
Closed

Opening/Reading character device #1395

joernheissler opened this issue Feb 9, 2020 · 4 comments

Comments

@joernheissler
Copy link

Hello,
I tried reading /dev/input/event0 with trio. This character device generates a byte stream of events.
Only function I could find is trio.open_file, but looks like its purpose is actual files.
How can I open a character device so I'll get some trio.abc.ReceiveStream?

Thanks!

@pquentin
Copy link
Member

pquentin commented Feb 9, 2020

A shot in the dark: would FdStream help? https://trio.readthedocs.io/en/stable/reference-hazmat.html#unix-specific-api

@njsmith
Copy link
Member

njsmith commented Feb 9, 2020 via email

@joernheissler
Copy link
Author

Thanks, I wasn't aware of trio.hazmat.FdStream. Works like a charm: https://gist.github.com/joernheissler/b366aae6b5067a5d71b2e46a5e6d5d63

I think it would still be great to have a function which handles os.open and trio.hazmat.FdStream for the user.

@oremanj
Copy link
Member

oremanj commented May 12, 2020

The combination of os.open() + wrapping in FdStream that is possible with Trio's actual current APIs would only work for some devices and named pipes, not most files on disk (nor stdin, for example). I think exposing a nice name for this combo might become a bit of an attractive nuisance wrt users expecting more from it than it's able to deliver.

Closing this in favor of #174 and #219 which discuss the more general problem of wrapping "anything you can open" in a nice API.

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

No branches or pull requests

4 participants