Questions tagged [keyboardinterrupt]

227 questions
5
votes
1 answer

tkinter keyboard interrupt isn't handled until tkinter frame is raised

I have a GUI application written with python+tkinter. In my workflow, I generally start the gui from the commandline, do some things in the gui and then I find myself navigating to other terminal windows to do some work. Inevitably, I want to shut…
mgilson
  • 264,617
  • 51
  • 541
  • 636
5
votes
0 answers

Is SIGINT intrinsically unreliable in python?

I have an application that relies on SIGINT for a graceful shutdown. I noticed that every once in awhile it just keeps running. The cause turned out to be a generator in xml/etree/ElementTree.py. If SIGINT arrives while that generator is being…
5
votes
1 answer

Python main thread interruption

Can anyone explain how the interrupt_main() method works in Python? I've got this piece of Python code : import time, thread def f(): time.sleep(5) thread.interrupt_main() def g(): thread.start_new_thread(f, ()) …
Danstahr
  • 3,902
  • 17
  • 34
5
votes
2 answers

Catch Keyboard Interrupt to stop Python multiprocessing worker from working on queue

From several posts found on stackoverflow i created this code. Scenario I want to have a multiprocessing.queue on which several worker "listen" In case of a keyboard interrupt, the main process should no longer put new items in the queue and with…
Dukeatcoding
  • 1,326
  • 2
  • 19
  • 30
5
votes
2 answers

Python threads with os.system() calls. Main thread doesn't exit on ctrl+c

Please don't consider it a duplicate before reading, There are a lot of questions about multithreading and keyboard interrupt, but i didn't find any considering os.system and it looks like it's important. I have a python script which makes some…
Shamdor
  • 2,699
  • 3
  • 20
  • 24
4
votes
3 answers

Why is my threading/multiprocessing python script not exiting properly?

I have a server script that I need to be able to shutdown cleanly. While testing the usual try..except statements I realized that Ctrl-C didn't work the usual way. Normally I'd wrap long running tasks like this try: ... except…
c00kiemonster
  • 19,305
  • 31
  • 84
  • 128
4
votes
4 answers

Can't kill my python code. What's wrong?

Okay, so I'm writing a very simplistic password cracker in python that brute forces a password with alphanumeric characters. Currently this code only supports 1 character passwords and a password file with a md5 hashed password inside. It will…
NiaKitty
  • 93
  • 4
4
votes
2 answers

Is there a way to never exit on KeyboardInterrupt in python?

I'm creating sort of a interactive command line in python. I have something like this: def complete_menu(): while True: cmd = input('cmd> ') if cmd == "help": print('help') elif cmd == "?": …
jackoboy
  • 51
  • 1
  • 4
4
votes
1 answer

Where does execution stop if keyboard interrupt is given as input?

I have this simple piece of code in a file named printftest.c. #include int main(){ int c, i; i = 0; while ((c = getchar()) != EOF) ++i; printf("c = %d\n", c); printf("i = %d\n", i); } Compilation and…
BramAppel
  • 1,198
  • 1
  • 6
  • 18
4
votes
1 answer

python gevent: unexpected output in KeyboardInterrupt

Running this code import gevent def f(): while True: gevent.sleep(1) if __name__ == '__main__': tasks = (gevent.spawn(f),) try: gevent.wait(tasks) except KeyboardInterrupt: print("KeyboardInterrupt…
4
votes
2 answers

twisted - interrupt callback via KeyboardInterrupt

I'm currently repeating a task in a for loop inside a callback using Twisted, but would like the reactor to break the loop in the callback (one) if the user issues a KeyboardInterrupt via Ctrl-C. From what I have tested, the reactor only stops or…
user500869
  • 123
  • 1
  • 5
4
votes
2 answers

Ctrl-C ends my script but it is not caught by KeyboardInterrupt exception

I have a Python script that contains a big loop reading a file and doing some stuff (I am using several packages like urllib2, httplib2 or BeautifulSoup). It looks like this : try: with open(fileName, 'r') as file : for i, line in…
Thematrixme
  • 238
  • 1
  • 3
  • 13
4
votes
2 answers

Switching writing from file to stdout using "sink()" in R

I implemented the following procedure that aims to write some files and print a message in the end of each file when the writing is done: # Print one file per piaf output_dir_piafs <- "OUTPUT_dataset_piafs" unlink(output_dir_piafs, recursive = TRUE,…
Gauthier Boaglio
  • 9,308
  • 4
  • 43
  • 81
4
votes
2 answers

a custom interrupt handler for mpirun

Apparently, mpirun uses a SIGINT handler which "forwards" the SIGINT signal to each of the processes it spawned. This means you can write an interrupt handler for your mpi-enabled code, execute mpirun -np 3 my-mpi-enabled-executable and then SIGINT…
Ammar
  • 563
  • 4
  • 14
3
votes
2 answers

KeyboardInterrupt Exception

I'm having a hard time handling Exceptions in pycharm 3.8: When I press ctrl+c running my program, it doesn't work, so I've been told to use pycharm console to test it, and it does work, interrupting the keyboard input. def readFloat(msg): while…
1 2
3
15 16