Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Input() blocks IDE from stopping a program

I've got a program with a console menu. I use input() to, well, get user input. But when I want to force-restart/terminate program execution in PyCharm or close IDE entirely, the program keeps running until I enter anything.

This snippet is a stripped-down version:

while True:
    inp = input()
    if inp == 'hi':
        print('hello there')

    elif inp == 'exit':
        break

    else:
        print('unknown command')

and prints out in console:

KeyboardInterrupt

Process finished with exit code -1073741510 (0xC000013A: interrupted by Ctrl+C)

I've done some research:

  1. -This is probably an IDE-only issue, as...
  2. -Enabling "Emulate terminal in output console" stops this bug from occurring.

But I think it's just a workaround, and I'd like to know more about why this is happening. Also have you encountered this before?

like image 569
aventadoro-ish Avatar asked Apr 25 '26 16:04

aventadoro-ish


1 Answers

2021.2 PyCharm tries to gracefully terminate processes on Windows with WinP instead of killing them as it used to be. That's probably is a reasonable behavior - once you click "Stop" once Ctrl+C should be sent, the next click on "Stop" should kill the process. It works this way on Linux and macOS (SIGINT and SIGKILL). Unfortunately, the new behavior has a bug leading to a bunch of issues.

Try the following inside the IDE to revert to the old behavior

  1. "Help | Find Action | Registry" menu
  2. Disable use.winp.for.graceful.process.termination
  3. Restart PyCharm

See the relevant ticket in PyCharm's bug tracker:

  • PY-50207 Unexpected change: "Stop" button sends SIGINT on Windows instead of killing the process as it used to
like image 175
Pavel Karateev Avatar answered Apr 27 '26 05:04

Pavel Karateev