Powershell: Powershell 6 exits the terminal when Ctrl-C is pushed when running a python script.

Created on 29 Nov 2019  路  14Comments  路  Source: PowerShell/PowerShell

Steps to reproduce

2019-11-29_08-28-16

If I open a terminal with new pwsh.exe and press ^c all is ok. If I start python and press ^c it kills the terminal instead of just python.

This does not happen with powershell 5 a.k.a powershell.exe

My profile for the windows terminal in case anybody thinks this might be a problem is

    {
        "guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
        "name": "Windows PowerShell",
        "commandline": "C:/Users/brad/.dotnet/tools/pwsh.exe",
        "hidden": false,
        "startingDirectory": "d:\\sandboxes",
        "colorScheme": "Campbell"
    },

Expected behavior

The terminal is not closed.

Actual behavior

The terminal closes

Environment data

Name                           Value
----                           -----
PSVersion                      6.2.3
PSEdition                      Core
GitCommitId                    6.2.3
OS                             Microsoft Windows 10.0.18362
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0鈥
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

I've tried this in the new windows terminal and the older console and it is not specific to the console type. pwsh.exe seems to be the problem.

Extra Info

What is even weirder. If you start a powershell 5 terminal powershell.exe and then from within that run pwsh.exe and then start python (2.7) and then press ctrl-c the terminal doesn't exit but the keyboard input is totally messed up. Sometimes it doesn't even register a keypress or moves the cursor somewhere else in the terminal.

Issue-Question WG-Interactive-Console

All 14 comments

Can you repo with out PSReadline?

I had a few handlers for PSReadline and I removed them from my profile. In fact I cleared my profile completely. It didn't change anything. The above noted behaviour continues.

If you meant for me to do something else then can you be a bit more specific. Uninstall something perhapps?

Please remove PSReadline - Remove-Module PSReadline - and try again.

Doesn't seem to make a difference. When you see ^S it just confirms that my PSReadline handlers are definitely not working anymore and thus the

Remove-Module PSReadline

has worked.

D3bLIZLnrD

Have you been able to replicate the problem?

I guess it again comes from how PowerShell communicates with a terminal.
/cc @rjmholt @SteveL-MSFT

Clearing my powershell profile and running Remove-Module PSReadline did not resolve the issue for me. Any idea what i can do?

image

Environment data

PowerShell

Name                           Value
----                           -----
PSVersion                      6.2.4
PSEdition                      Core
GitCommitId                    6.2.4
OS                             Microsoft Windows 10.0.18363
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0鈥
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Windows Terminal

Windows Terminal (Preview)
Version: 0.8.10261.0

I haven't been able to reproduce this myself yet, but a few things worth trying:

  • In the first case PowerShell is installed as a dotnet global tool. If you try MSI installation, does this issue persist?
  • If you can, please try this with the current PowerShell 7 release to see if it reproduces. There have been many changes in PowerShell since 6, not just in our code but in the move to .NET Core 3.1 (PS 6 is on .NET Core 2.1)

If you're able to reproduce this there, we can hopefully fix it for PowerShell 7.1.

PowerShell 7 RC2 does not change the outcome:

Name                           Value
----                           -----
PSVersion                      7.0.0-rc.2
PSEdition                      Core
GitCommitId                    7.0.0-rc.2
OS                             Microsoft Windows 10.0.18363
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0鈥
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

image

The same behavior when using the msi installer for PowerShell 6.2.4 and 7.0.0 RC2.

After some more testing i found that this issue only occures when powershell is started from Windows Terminal. I wan't able to reproduce this issue when powershell 6 or 7 was startet directly or via cmd.

So maybe moving this issue to the Windows Terminal project?

This might be the same issue as https://github.com/PowerShell/PowerShell/issues/11215

Edit: nevermind this issue is Windows, the other one is specifically non-Windows so different issues

There are strange effects with the non "windows terminal" shells. For
example if in order

  • open powershell from start menu
  • start pwsh from the terminal
  • start python from the terminal
  • press ctrl-c

I am back in the shell but the terminal is completely messed up. Every key
press jumps the cursor around the terminal and it is impossible to perform
any more actions.

I've attached a video that shows the above operations. Note again this is not windows terminal it is the powershell terminal launched from start menu. I've also run the experiment with cmd.exe terminal and similar effects are demonstrated.

See the video

2020-02-05_09-17-33

How did you install pwsh? If you're using a shim rather than installing directly, it can cause this behaviour. See here: https://github.com/lukesampson/scoop/issues/3634 and https://github.com/felixse/FluentTerminal/issues/221

@bradphelan I think the behaviour you're seeing is a PSReadLine issue. If you rmo PSReadLine you shouldn't reproduce it. I also think it's an older PSRL issue and has been fixed in the latest version

I am seeing this in pwsh 7.0.2 too, btw. Funny thing is I only updated yesterday to it from 7.0.1, and I don't think I saw this before. This ~= "when I press ctrl-c, the entire shell shuts down and displays the [process exited message".

And yes, I did install PowerShell Core 7.0.2 through scoop install pwsh, so I guess this is a .ps1-shim thing, as @cubagithub mentioned.

Will try to see what changes if I use choco to install it :).

Was this page helpful?
0 / 5 - 0 ratings