keyboardinterrupt

How to set push-button to keyboard interrupt in PyQt

谁说胖子不能爱 提交于 2019-12-04 06:26:16
问题 While running program through the terminal we can stop the program by pressing 'Ctrl+c' and it will show the message as 'KeyboardInterrupt' . So, is there any way to do the sane thing by clicking the push-button in PyQt. 回答1: If your program is running a loop, you can call processEvents periodically to allow the gui time to update (which should allow you to click a button to close the application): count = 0 while True: count += 1 if not count % 50: QtGui.qApp.processEvents() # do stuff...

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

醉酒当歌 提交于 2019-12-04 03:56:05
问题 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 the help of the sentinel objects, the worker should gracefully be stopped. Problem My problem with the current version where i use signal.signal(signal.SIGINT, signal.SIG_IGN) To ignore the Ctrl + C is that it is also ignored by the main process. Any

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

家住魔仙堡 提交于 2019-12-01 19:08:53
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 the help of the sentinel objects, the worker should gracefully be stopped. Problem My problem with the current version where i use signal.signal(signal.SIGINT, signal.SIG_IGN) To ignore the Ctrl + C is that it is also ignored by the main process. Any Ideas ? Do I need to use the multiprocessing worker pool ? Some examples indicate that i might have to

a custom interrupt handler for mpirun

浪子不回头ぞ 提交于 2019-12-01 10:51:02
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 will be raised for each of the three processes. Shortly after that, mpirun exits. This works fine when you have a small custom handler which only prints an error message and then exits. However , when your custom interrupt handler is doing a non-trivial job (e.g. doing serious computations or persisting data), the handler does not run to completion.

a custom interrupt handler for mpirun

旧巷老猫 提交于 2019-12-01 08:18:57
问题 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 will be raised for each of the three processes. Shortly after that, mpirun exits. This works fine when you have a small custom handler which only prints an error message and then exits. However , when your custom interrupt handler is doing a non

twisted - interrupt callback via KeyboardInterrupt

 ̄綄美尐妖づ 提交于 2019-12-01 08:18:47
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 processes interrupts at the end of the callback. Is there any way of sending a KeyboardInterrupt to the callback or the error handler in the middle of the callback run? Cheers, Chris #!/usr/bin/env python from twisted.internet import reactor, defer def one(result): print "Start one()" for i in xrange(10000): print i print "End one()" reactor.stop()

twisted - interrupt callback via KeyboardInterrupt

让人想犯罪 __ 提交于 2019-12-01 04:09:50
问题 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 processes interrupts at the end of the callback. Is there any way of sending a KeyboardInterrupt to the callback or the error handler in the middle of the callback run? Cheers, Chris #!/usr/bin/env python from twisted.internet import reactor, defer

Selenium: Quit Python script without closing browser

老子叫甜甜 提交于 2019-11-30 22:52:31
I use the following to handle the situation where Ctrl + C is used to terminate a running Python script. except KeyboardInterrupt: print "ABORTED" However, this also terminates my Selenium WebDriver browser. Is there a way to terminate the script and keep the browser alive, so that I can continue using it? What I usually do instead, is to pause the script via Ctrl + Z . This unfortunately often causes the browser to freeze and not respond. You can replace CTRL+C+ sys.exit() with quit() method to terminate Python script without closing browser session. Just use following form: user_choice = raw

User input with a timeout, in a loop

a 夏天 提交于 2019-11-30 09:00:19
问题 I'm trying to create a looping python function which performs a task and prompts the user for a response and if the user does not respond in the given time the sequence will repeat. This is loosely based off this question: How to set time limit on raw_input The task is represented by some_function() . The timeout is a variable in seconds. I have two problems with the following code: The raw_input prompt does not timeout after the specified time of 4 seconds regardless of whether the user

Selenium: Quit Python script without closing browser

让人想犯罪 __ 提交于 2019-11-30 05:19:55
问题 I use the following to handle the situation where Ctrl + C is used to terminate a running Python script. except KeyboardInterrupt: print "ABORTED" However, this also terminates my Selenium WebDriver browser. Is there a way to terminate the script and keep the browser alive, so that I can continue using it? What I usually do instead, is to pause the script via Ctrl + Z . This unfortunately often causes the browser to freeze and not respond. 回答1: You can replace CTRL+C+ sys.exit() with quit()