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

Freeze on process.iseof() #423

Open
shadoxxhd opened this issue Jun 6, 2024 · 7 comments
Open

Freeze on process.iseof() #423

shadoxxhd opened this issue Jun 6, 2024 · 7 comments

Comments

@shadoxxhd
Copy link

When trying to automate steamcmd (https://developer.valvesoftware.com/wiki/SteamCMD), I found a condition where pywinpty freezes when process.isoef() is called:

from winpty import PTY
proc = PTY(80,10)
proc.spawn("steamcmd.exe +login None None +quit")
while not proc.iseof():
  pass

This seems to be the minimal example - I don't know what the trigger is exactly, but when the login is successful (real user/password combination instead of "None None", or even just "anonymous"), it doesn't cause winpty to freeze. Importantly, it doesn't get stuck in the loop - the proc.iseof() instruction itself freezes in that condition, even when trying to step into it with pdb!

@andfoy
Copy link
Owner

andfoy commented Jun 7, 2024

Hi @shadoxxhd, thanks for the report! Could you please check if this behavior occurs when the executable is called in CMD/Terminal?

@shadoxxhd
Copy link
Author

Running the executable from the terminal with these inputs doesn't cause any freeze.

@shadoxxhd
Copy link
Author

Should I open an issue in the wintpy-rs repo for this?

@andfoy
Copy link
Owner

andfoy commented Jun 21, 2024

Hi @shadoxxhd, I haven't got time to check this issue. A release for both packages is pending, I'll check it by that time.

In the meantime, feel free to explore the codebase at winpty-rs to see if something comes up that could be related to this specific issue. Any contribution is welcome

@shadoxxhd
Copy link
Author

Hi, did you end up looking into this?

I am unsure how I'd go about debugging this, especially without having any rust development environment set up.

@andfoy
Copy link
Owner

andfoy commented Aug 30, 2024

@shadoxxhd, sorry for the delay in answering, I need to fix some issues in the latest winpty-rs release related to exit/EOF, hopefully this will address this issue

@shadoxxhd
Copy link
Author

In trying to find a workaround for the iseof issue, I encountered another problem related to exit/EOF. You seem to be aware of the issue, but in case it helps:

PtyProcess can apparently get stuck on .readline()/.read(); it keeps blocking after the program is no longer alive (hanging in fileobj.recv until conhost.exe is manually terminated).

Having a separate thread call .close() at some point helped it get unstuck, but in my latest tests, it did not (perhaps it only helps for readline, and not for read??).

Using the PTY and .read()ing while .isalive() without calling .iseof() seems to be a workaround.

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

2 participants