keyboardinterrupt

Python 2.7: Child thread not catching KeyboardInterrupt

寵の児 提交于 2019-12-24 14:53:00
问题 import sys import time import threading class exThread(threading.Thread): def __init__(self, threadId): threading.Thread.__init__(self) self.threadId = threadId def run(self): try: while 1: pass except KeyboardInterrupt: print "Ctrl-C caught by thread" finally: print "Thread's finally clause being executed" sys.exit() # Same as thread.exit() cond = True def func(): pass try: th = exThread(1) th.start() while True: if cond: func() except KeyboardInterrupt: print "Ctrl-C caught by main thread"

x86 assembler interrupts code

↘锁芯ラ 提交于 2019-12-24 09:13:26
问题 #include <studio.h> #include <dos.h> void interrupt (*int9save) (void) void interrupt eliminate_multiple_press(void) { int9save=getvect(9); setvect(9,eliminate_multiple_press); asm { MOV AH,0 int 16h MOV scan_temp,AH CMP ZF,0 } } void interrupt uneliminate_multiple_press() { setvect(9,int9save); } void main(void) { char str[100]; int check=1; char scan_temp; unsigned int scan_code ; eliminate_multiple_press(); printf("enter a word\n"); scanf("%s",str); scan_code=(unsigned int) scan_temp;

When is KeyboardInterrupt raised in Python?

夙愿已清 提交于 2019-12-22 04:12:17
问题 All the docs tell us is, Raised when the user hits the interrupt key (normally Control-C or Delete ). During execution, a check for interrupts is made regularly. But from the point of the code, when can I see this exception? Does it occur during statement execution? Only between statements? Can it happen in the middle of an expression? For example: file_ = open('foo') # <-- can a KeyboardInterrupt be raised here, after the successful # completion of open but prior to the try? --> try: # try

KeyboardInterrupt multiple threads at once

我的未来我决定 提交于 2019-12-21 06:36:13
问题 I am currently working with several threads to collect data and save it in a JSON. The loop to collect the data is infinite. I want to be able to end all the threads with CTRL+C. Therefore I created this simple version with two loops. I have tried different things, but can't make it work so far. How can I use "except KeyboardInterrupt" to stop both loops at once? Or is there a better option? import threading from time import sleep number = 0 numberino = 10 def background(): while True: if

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

♀尐吖头ヾ 提交于 2019-12-18 08:28:12
问题 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 down the GUI at some point, and out of habit I often just navigate to the terminal that started the GUI and send a KeyboardInterrupt (Ctrl-c). However, This interrupt is not recieved until I raise the GUI window in the Window manager. Does anyone

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

…衆ロ難τιáo~ 提交于 2019-12-18 08:27:45
问题 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 down the GUI at some point, and out of habit I often just navigate to the terminal that started the GUI and send a KeyboardInterrupt (Ctrl-c). However, This interrupt is not recieved until I raise the GUI window in the Window manager. Does anyone

Python: How to prevent subprocesses from receiving CTRL-C / Control-C / SIGINT

好久不见. 提交于 2019-12-17 21:49:22
问题 I am currently working on a wrapper for a dedicated server running in the shell. The wrapper spawns the server process via subprocess and observes and reacts to its output. The dedicated server must be explicitly given a command to shut down gracefully. Thus, CTRL-C must not reach the server process. If I capture the KeyboardInterrupt exception or overwrite the SIGINT-handler in python, the server process still receives the CTRL-C and stops immediately. So my question is: How to prevent

Why doesn't this python keyboard interrupt work? (in pycharm)

本秂侑毒 提交于 2019-12-17 16:37:09
问题 My python try/except loop does not seem to trigger a keyboard interrupt when Ctrl + C is pressed while debugging my code in pycharm. My code look like this: numbers = [] loop = True try: # ===========SUBROUTINES================== def help(): print("To view the list type 'view'" "\n To add an item type 'add'" "\n To remove an item type 'remove'" "\n To exit type exit or Ctrl + c can be used at any time") # =========SUBROUTENES END=============== while loop: task = input("What do you want to do

In Matlab, is it possible to terminate a script, but save all its internal variables to workspace?

孤人 提交于 2019-12-17 09:33:56
问题 I am running a script, but it is taking much too long so I want to terminate the script. However it has calculated a lot of data which I would ideally not want to throw away. Is there an alternative to ctrl-C with which you save the internal function variables to the workspace? Ideally I'm looking for a Matlab keyboard shortcut like ctrl-C , but if that really can't be done maybe there is a way to do this in the script of my function. Any idea how to let my script react to ctrl-C as well, or

threading ignores KeyboardInterrupt exception

霸气de小男生 提交于 2019-12-17 05:01:18
问题 I'm running this simple code: import threading, time class reqthread(threading.Thread): def run(self): for i in range(0, 10): time.sleep(1) print('.') try: thread = reqthread() thread.start() except (KeyboardInterrupt, SystemExit): print('\n! Received keyboard interrupt, quitting threads.\n') But when I run it, it prints $ python prova.py . . ^C. . . . . . . . Exception KeyboardInterrupt in <module 'threading' from '/usr/lib/python2.6/threading.pyc'> ignored In fact python thread ignore my