-
Notifications
You must be signed in to change notification settings - Fork 71
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
is it possible to PtyProcess.read() without blocking? #48
Comments
Pexpect has a |
gevent's term.pty = PtyProcessUnicode.spawn(term.cmd, env=env, cwd=opts.get("cwd", None)) and then def from_pty(wsock_xtermjs_observer):
while True:
b = gevent_os.tp_read(term.pty.fd, 65536).decode("utf-8")
wsock_xtermjs_observer.on_next(["stdout", b]) works like a charm, i.e. does not block other greenlets with Other more manual method would be using readable, _, _ = select.select([pty.fd], [], [], timeout) PS: No silly question, my kids did not get their fairytale yesterday evening, because of this :-/ |
@axgkl one thing though: how are you detecting when the process has ended / there is no data left, so you can break the from the docs "If end-of-file is reached, an empty string is returned.", and based on that, the following is not working: while True:
# proc is an instance of PtyProcessUnicode
data = gevent_os.tp_read(proc.fd, 65536)
if not data:
break
use(data) because I get a I've tried while not proc.closed:
data = gevent_os.tp_read(proc.fd, 65536)
use(data) but it's the same issue thank you very much |
I'm running ptyprocess in read in a greenlet coroutine. so when I .read() and there's no data, it blocks and stops all the other greenlets. is it possible to read without blocking, or at least check if there's any new data?
Sorry it this is a silly question
Thank you
The text was updated successfully, but these errors were encountered: