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;








0















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.










share|improve this question
























  • 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

















0















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.










share|improve this question
























  • 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













0












0








0








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.










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 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
















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












1 Answer
1






active

oldest

votes


















1














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/






share|improve this answer























  • 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











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
);



);













draft saved

draft discarded


















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









1














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/






share|improve this answer























  • 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















1














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/






share|improve this answer























  • 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













1












1








1







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/






share|improve this answer













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/







share|improve this answer












share|improve this answer



share|improve this answer










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

















  • 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



















draft saved

draft discarded
















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현