pywinpty icon indicating copy to clipboard operation
pywinpty copied to clipboard

Constructing PTY instance kills terminal

Open abingham opened this issue 4 years ago • 9 comments

When I try to construct a PTY instance, it terminates my terminal program. With both cmd.exe and PowerShell, the following program will kill my terminal as soon as I execute the PTY constructor:

from winpty import PTY
PTY(10, 10, 'utf-8', None)

Strangely, the terminal built in to VSCode seems to behave correctly when I do the same thing.

This is on Windows 10, build 19043.1237. I'm running Windows under Parallels Desktop 17 on macos 11.6.

I'm at a loss as to how to proceed. Any idea what's going on? Or is there something I can do to help diagnose it?

abingham avatar Oct 04 '21 07:10 abingham

Hi @abingham, thanks for reaching out! I have a question, does any error message comes up? Or did it fail immediately? Also, have you tried setting a backend directly?

from winpty import PTY, Backend

pty = PTY(80, 25, backend=Backend.WinPTY)

andfoy avatar Oct 06 '21 23:10 andfoy

I have a question, does any error message comes up? Or did it fail immediately?

It appears to fail immediately. The window disappears right away. If there are any messages being printed, I'm not able to see them.

Also, have you tried setting a backend directly?

This seems to make things work! Thanks for pointing that out.

abingham avatar Oct 07 '21 05:10 abingham

Sorry, didn't mean to close this.

It seems like I should be able to use the ConPTY backend, so is there more I should try?

abingham avatar Oct 07 '21 05:10 abingham

Also, it appears that the backend argument to PtyProcess.spawn is ignored. On ptyprocess.py:93, the backend variable is overwritten with the value of the PYWINPTY_BACKEND environment variable. This is a tangential issue, but I thought it was worth mentioning. Is the intent that the backend argument should be used unless the environment variable is set?

abingham avatar Oct 07 '21 06:10 abingham

It seems like I should be able to use the ConPTY backend, so is there more I should try?

Did all backends worked as expected when called explicitly? i.e., Backend.ConPTY and Backend.WinPTY?

Is the intent that the backend argument should be used unless the environment variable is set?

This is actually an error on our part, we should not ignore the backend value in PtyProcess if the environment variable is not set. However, PtyProcess is a higher-level interface that wraps PTY, so this bug is not related to the initial reported failure. Thanks for pointing it out

andfoy avatar Oct 07 '21 17:10 andfoy

Did all backends worked as expected when called explicitly? i.e., Backend.ConPTY and Backend.WinPTY?

No, it works with WinPTY but fails with the initially reported behavior when I use ConPTY.

abingham avatar Oct 08 '21 05:10 abingham

I think the only sensible step to take here is to try to debug on MSVC to see what's happening, you can either put std::cout prints in https://github.com/spyder-ide/pywinpty/blob/36b4c00ca1a89f67edd06db508b495d044aaf6d2/src/csrc/conpty_common.cpp#L75 or using DebugEnv (https://docs.microsoft.com/en-us/visualstudio/ide/reference/debugexe-devenv-exe?view=vs-2019) on python.exe, please let me know if you require further pointers

andfoy avatar Oct 11 '21 16:10 andfoy

Hi @abingham, could you please indicate if this issue still occurs with the latest version?

andfoy avatar Mar 03 '22 23:03 andfoy

I will try to do this sometime soon. My windows 10 system was retired, though I think I might be able to spin it up for this.

abingham avatar Mar 07 '22 06:03 abingham