keyboardinterrupt

Python selenium CTRL+C closes chromedriver

北城以北 提交于 2021-02-07 20:27:06
问题 How can I catch CTRL+C (a KeyboardInterrupt) without causing the chromedriver to close. It closes the chromedriver when I run my script.py through cmd. driver = webdriver.Chrome() try: while True: #do stuff with chromedriver except KeyboardInterrupt: print "User pressed CTRL + C" #do other stuff with chromedriver It does catch the KeyboardInterrupt in my script, thus my script continues but the chromedriver also gets it and close itself. EDIT 1: The solution here doesn't work when you run the

how to stop execution on KeyboardInterrupt while using multiprocessing.Pool #python [duplicate]

主宰稳场 提交于 2020-02-04 01:26:53
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Keyboard Interrupts with python's multiprocessing Pool Python's multiprocessing module has something called Pool http://docs.python.org/library/multiprocessing.html#module-multiprocessing.pool While a pool of processes is operating, I can't get the script to terminate using KeyboardInterrupt i.e Ctrl + c. The pool spawns new processes and the only way to get out is ctrl + z followed by killing them manually.

Pause for an event in python tkinter

≯℡__Kan透↙ 提交于 2020-01-06 18:04:30
问题 I am using a python 2.7 tkinter gui on a raspberry pi to automate some material testing. For the testing, multiple samples must be tested and it takes time to swap out the samples. I want to prompt text saying something like "Please insert sample one then press enter on keyboard" and have the function pause until enter has been pressed. Instead of pressing enter I could also use a tkinter button. Any ideas without using external libraries? I have tried a while loop in which I try and exit the

Pause for an event in python tkinter

青春壹個敷衍的年華 提交于 2020-01-06 18:03:27
问题 I am using a python 2.7 tkinter gui on a raspberry pi to automate some material testing. For the testing, multiple samples must be tested and it takes time to swap out the samples. I want to prompt text saying something like "Please insert sample one then press enter on keyboard" and have the function pause until enter has been pressed. Instead of pressing enter I could also use a tkinter button. Any ideas without using external libraries? I have tried a while loop in which I try and exit the

KeyboardInterrupt taking a while

不羁岁月 提交于 2020-01-03 10:05:05
问题 So I just started messing around with Python on Linux, using Tkinter. I'm trying to make Cntrl+C stop execution by using the KeyboardInterrupt Exception, but when i press it nothing happens for a while. Eventually it "takes" and exits. A little bit of reading suggests this might have to do with threading or something, but i'm so new to this stuff i'm really not sure where to begin. #! /usr/bin/python import sys from Tkinter import * try: root = Tk() root.mainloop() except: print "you pressed

KeyboardInterrupt taking a while

[亡魂溺海] 提交于 2020-01-03 10:02:16
问题 So I just started messing around with Python on Linux, using Tkinter. I'm trying to make Cntrl+C stop execution by using the KeyboardInterrupt Exception, but when i press it nothing happens for a while. Eventually it "takes" and exits. A little bit of reading suggests this might have to do with threading or something, but i'm so new to this stuff i'm really not sure where to begin. #! /usr/bin/python import sys from Tkinter import * try: root = Tk() root.mainloop() except: print "you pressed

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

吃可爱长大的小学妹 提交于 2020-01-01 10:57:15
问题 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 external calls in worker threads. I want it to exit if I press ctrl+c But it look like the main thread ignores it. Something like this: from threading import Thread import sys import os def run(i): while True: os.system("sleep 10") print i def main():

python multiprocessing BaseManager registered class lost connection immediately after Ctrl-C

≯℡__Kan透↙ 提交于 2019-12-29 07:21:10
问题 I am experiencing some issues that I suspect is a limitation of my python program to handle correctly, my program is not been able to call methods of a registered class of BaseManager immediately after I hit Ctrl-C, even other process implemented as classes that inherit from multiprocessing.Process are affected. I have some methods that I would like to call from process that don't execute correctly after Ctrl-C. For example the following code is not able to call the mt instance of TestClass

python multiprocessing BaseManager registered class lost connection immediately after Ctrl-C

感情迁移 提交于 2019-12-29 07:21:08
问题 I am experiencing some issues that I suspect is a limitation of my python program to handle correctly, my program is not been able to call methods of a registered class of BaseManager immediately after I hit Ctrl-C, even other process implemented as classes that inherit from multiprocessing.Process are affected. I have some methods that I would like to call from process that don't execute correctly after Ctrl-C. For example the following code is not able to call the mt instance of TestClass

Why does the asyncio's event loop suppress the KeyboardInterrupt on Windows?

泄露秘密 提交于 2019-12-28 12:17:12
问题 I have this really small test program which does nothing apart from a executing an asyncio event loop: import asyncio asyncio.get_event_loop().run_forever() When I run this program on Linux and press Ctrl + C , the program will terminate correctly with a KeyboardInterrupt exception. On Windows pressing Ctrl + C does nothing (tested with Python 3.4.2). A simple inifinite loop with time.sleep() raises the KeyboardInterrupt correctly even on Windows: import time while True: time.sleep(3600) Why