Catching only *one* KeyboardInterruptExceptionCatch multiple exceptions at once?The case against checked exceptionsGlobally catch exceptions in a WPF application?Catching / blocking SIGINT during system callCan I catch multiple Java exceptions in the same catch clause?Catch multiple exceptions in one line (except block)grep, but only certain file extensionsa custom interrupt handler for mpirunHow to ignore keyboardInterrupt Exception in a module and deal with it in higher level in winpexpet?python picamera, keyboard ctrl+c/sigint not caught
Could the terminal length of components like resistors be reduced?
How did Captain America manage to do this?
What's the polite way to say "I need to urinate"?
What is the most expensive material in the world that could be used to create Pun-Pun's lute?
Relationship between strut and baselineskip
555 timer FM transmitter
How does Captain America channel this power?
a sore throat vs a strep throat vs strep throat
Is it idiomatic to construct against `this`
"Whatever a Russian does, they end up making the Kalashnikov gun"? Are there any similar proverbs in English?
What's the name of these pliers?
How come there are so many candidates for the 2020 Democratic party presidential nomination?
Can SQL Server create collisions in system generated constraint names?
Why do games have consumables?
Why didn't the Space Shuttle bounce back into space as many times as possible so as to lose a lot of kinetic energy up there?
How do I deal with a coworker that keeps asking to make small superficial changes to a report, and it is seriously triggering my anxiety?
acheter à, to mean both "from" and "for"?
How do I reattach a shelf to the wall when it ripped out of the wall?
Does a large simulator bay have standard public address announcements?
Why was the Spitfire's elliptical wing almost uncopied by other aircraft of World War 2?
Implications of cigar-shaped bodies having rings?
I preordered a game on my Xbox while on the home screen of my friend's account. Which of us owns the game?
How do I check if a string is entirely made of the same substring?
How to fry ground beef so it is well-browned
Catching only *one* KeyboardInterruptException
Catch multiple exceptions at once?The case against checked exceptionsGlobally catch exceptions in a WPF application?Catching / blocking SIGINT during system callCan I catch multiple Java exceptions in the same catch clause?Catch multiple exceptions in one line (except block)grep, but only certain file extensionsa custom interrupt handler for mpirunHow to ignore keyboardInterrupt Exception in a module and deal with it in higher level in winpexpet?python picamera, keyboard ctrl+c/sigint not caught
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I have a long-running task that may be interrupted because an exception is raised inside it, or because Control+C is pressed signaling a SIGINT
, raising a KeyboardInterruptException
.
In both of these cases, the path to follow is to store the results that are already processed by the task, to prevent the lose of the computing time. This store takes some time, as it may need to process a good amount of information. The problem appears when Control+C is pressed again when the interrupt has already been caught.
Example:
task = SomeTask()
try:
task.start()
except KeyboardInterruptException:
print("Keyboard interrupted")
except Exception as e:
print_exception(e) # To show what happened
finally:
task.store_results() # If Control-C is pressed here, data gets corrupted
I need a way to catch the interrupt, launch the store process and prevent another interrupt from happening.
python unix exception keyboardinterrupt
add a comment |
I have a long-running task that may be interrupted because an exception is raised inside it, or because Control+C is pressed signaling a SIGINT
, raising a KeyboardInterruptException
.
In both of these cases, the path to follow is to store the results that are already processed by the task, to prevent the lose of the computing time. This store takes some time, as it may need to process a good amount of information. The problem appears when Control+C is pressed again when the interrupt has already been caught.
Example:
task = SomeTask()
try:
task.start()
except KeyboardInterruptException:
print("Keyboard interrupted")
except Exception as e:
print_exception(e) # To show what happened
finally:
task.store_results() # If Control-C is pressed here, data gets corrupted
I need a way to catch the interrupt, launch the store process and prevent another interrupt from happening.
python unix exception keyboardinterrupt
Suggest you add and OS tag to your question—because handlingSIGINT
varies depending on what operating system you're using.
– martineau
Mar 22 at 18:15
add a comment |
I have a long-running task that may be interrupted because an exception is raised inside it, or because Control+C is pressed signaling a SIGINT
, raising a KeyboardInterruptException
.
In both of these cases, the path to follow is to store the results that are already processed by the task, to prevent the lose of the computing time. This store takes some time, as it may need to process a good amount of information. The problem appears when Control+C is pressed again when the interrupt has already been caught.
Example:
task = SomeTask()
try:
task.start()
except KeyboardInterruptException:
print("Keyboard interrupted")
except Exception as e:
print_exception(e) # To show what happened
finally:
task.store_results() # If Control-C is pressed here, data gets corrupted
I need a way to catch the interrupt, launch the store process and prevent another interrupt from happening.
python unix exception keyboardinterrupt
I have a long-running task that may be interrupted because an exception is raised inside it, or because Control+C is pressed signaling a SIGINT
, raising a KeyboardInterruptException
.
In both of these cases, the path to follow is to store the results that are already processed by the task, to prevent the lose of the computing time. This store takes some time, as it may need to process a good amount of information. The problem appears when Control+C is pressed again when the interrupt has already been caught.
Example:
task = SomeTask()
try:
task.start()
except KeyboardInterruptException:
print("Keyboard interrupted")
except Exception as e:
print_exception(e) # To show what happened
finally:
task.store_results() # If Control-C is pressed here, data gets corrupted
I need a way to catch the interrupt, launch the store process and prevent another interrupt from happening.
python unix exception keyboardinterrupt
python unix exception keyboardinterrupt
edited Mar 22 at 19:16
0xfede7c8
asked Mar 22 at 17:36
0xfede7c80xfede7c8
31
31
Suggest you add and OS tag to your question—because handlingSIGINT
varies depending on what operating system you're using.
– martineau
Mar 22 at 18:15
add a comment |
Suggest you add and OS tag to your question—because handlingSIGINT
varies depending on what operating system you're using.
– martineau
Mar 22 at 18:15
Suggest you add and OS tag to your question—because handling
SIGINT
varies depending on what operating system you're using.– martineau
Mar 22 at 18:15
Suggest you add and OS tag to your question—because handling
SIGINT
varies depending on what operating system you're using.– martineau
Mar 22 at 18:15
add a comment |
1 Answer
1
active
oldest
votes
Just set the signal handler:
import signal
task = SomeTask()
try:
task.start()
except KeyboardInterruptException:
print("Keyboard interrupted")
except Exception as e:
print_exception(e) # To show what happened
finally:
signal.signal(signal.SIGINT, lamda *_: print('Wait!'))
task.store_results() # If Control-C is pressed here, data gets corrupted
Source: https://pythonadventures.wordpress.com/2012/11/21/handle-ctrlc-in-your-script/
This did the trick for me. It has less side effects because the first time it enters through the try/except and then it disables the interrupt :) Thanks
– 0xfede7c8
Mar 22 at 19:17
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55305047%2fcatching-only-one-keyboardinterruptexception%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Just set the signal handler:
import signal
task = SomeTask()
try:
task.start()
except KeyboardInterruptException:
print("Keyboard interrupted")
except Exception as e:
print_exception(e) # To show what happened
finally:
signal.signal(signal.SIGINT, lamda *_: print('Wait!'))
task.store_results() # If Control-C is pressed here, data gets corrupted
Source: https://pythonadventures.wordpress.com/2012/11/21/handle-ctrlc-in-your-script/
This did the trick for me. It has less side effects because the first time it enters through the try/except and then it disables the interrupt :) Thanks
– 0xfede7c8
Mar 22 at 19:17
add a comment |
Just set the signal handler:
import signal
task = SomeTask()
try:
task.start()
except KeyboardInterruptException:
print("Keyboard interrupted")
except Exception as e:
print_exception(e) # To show what happened
finally:
signal.signal(signal.SIGINT, lamda *_: print('Wait!'))
task.store_results() # If Control-C is pressed here, data gets corrupted
Source: https://pythonadventures.wordpress.com/2012/11/21/handle-ctrlc-in-your-script/
This did the trick for me. It has less side effects because the first time it enters through the try/except and then it disables the interrupt :) Thanks
– 0xfede7c8
Mar 22 at 19:17
add a comment |
Just set the signal handler:
import signal
task = SomeTask()
try:
task.start()
except KeyboardInterruptException:
print("Keyboard interrupted")
except Exception as e:
print_exception(e) # To show what happened
finally:
signal.signal(signal.SIGINT, lamda *_: print('Wait!'))
task.store_results() # If Control-C is pressed here, data gets corrupted
Source: https://pythonadventures.wordpress.com/2012/11/21/handle-ctrlc-in-your-script/
Just set the signal handler:
import signal
task = SomeTask()
try:
task.start()
except KeyboardInterruptException:
print("Keyboard interrupted")
except Exception as e:
print_exception(e) # To show what happened
finally:
signal.signal(signal.SIGINT, lamda *_: print('Wait!'))
task.store_results() # If Control-C is pressed here, data gets corrupted
Source: https://pythonadventures.wordpress.com/2012/11/21/handle-ctrlc-in-your-script/
answered Mar 22 at 17:50
ADRADR
767315
767315
This did the trick for me. It has less side effects because the first time it enters through the try/except and then it disables the interrupt :) Thanks
– 0xfede7c8
Mar 22 at 19:17
add a comment |
This did the trick for me. It has less side effects because the first time it enters through the try/except and then it disables the interrupt :) Thanks
– 0xfede7c8
Mar 22 at 19:17
This did the trick for me. It has less side effects because the first time it enters through the try/except and then it disables the interrupt :) Thanks
– 0xfede7c8
Mar 22 at 19:17
This did the trick for me. It has less side effects because the first time it enters through the try/except and then it disables the interrupt :) Thanks
– 0xfede7c8
Mar 22 at 19:17
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55305047%2fcatching-only-one-keyboardinterruptexception%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Suggest you add and OS tag to your question—because handling
SIGINT
varies depending on what operating system you're using.– martineau
Mar 22 at 18:15