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

A way to read standard input in the background without file/read in a thread. #1398

Open
amano-kenji opened this issue Feb 10, 2024 · 4 comments

Comments

@amano-kenji
Copy link
Contributor

amano-kenji commented Feb 10, 2024

Right now, stdin is a file. I have to use file/read in a thread.

I can't kill the program with (os/exit 1) which is blocked by file/read.

@amano-kenji amano-kenji changed the title A way to read standard input in the background without a thread. A way to read standard input in the background without file/read in a thread. Feb 10, 2024
@llmII
Copy link
Contributor

llmII commented Feb 11, 2024

I don't think Janet has a way at the moment, but I seem to recall one can close all the std* files, then reopen them by file descriptors. If there was a way to operate */open on file descriptors (integers) for I think FD 0, 1, and 2 - that would solve the issue. If what was opened was returned as a stream instead of a file (like how os/open does) then it'd be async-able.

@bakpakin
Copy link
Member

Building on this, I have recently pushed code that extends os/exit with a force parameter which allows calling _exit instead of exit. This circumvents the issue where exit needs to flush the standard streams before completing, which in some cases may fail. Unfortunately, this seems to be required by the C standard as detailed here - https://en.cppreference.com/w/c/program/exit ("all C streams are flushed and closed") The async streams though may be the better solutions.

@amano-kenji
Copy link
Contributor Author

amano-kenji commented Feb 27, 2024

Is it difficult to implement stdin as core/stream?

@amano-kenji
Copy link
Contributor Author

(os/exit 1 true) can be a way to solve this issue, too.

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

3 participants