How do I trap KeyboardInterrupt?

44 views
Skip to first unread message

richard

unread,
Jan 2, 2008, 6:49:14 AM1/2/08
to nose-users
I want to catch the KeyboardInterrupt exception so that the test
application exits gracefully (i.e. kills sub-processes and suppresses
the default stack trace output) but I can't see a way of doing this.

I considered an ErrorClass plug-in but that doesn't seem to permit
execution of arbitrary code like a clean-up routine.

I have built a normal plug-in that implements stopTest(), however that
requires several Ctrl-C interrupts before it is executed and only
applies when tests are running, whereas I may wish to terminate the
application during the initialisation phase.

Any ideas?


Thanks ...

Richard

Kumar McMillan

unread,
Jan 2, 2008, 2:11:20 PM1/2/08
to nose-...@googlegroups.com
On Jan 2, 2008 5:49 AM, richard <ebiz...@gmail.com> wrote:
>
> I want to catch the KeyboardInterrupt exception so that the test
> application exits gracefully (i.e. kills sub-processes and suppresses
> the default stack trace output) but I can't see a way of doing this.

AFAIK, KeyboardInterrupt is purposefully ignored by nose internals
everywhere so that the exception can do exactly what the name
suggests. Have you considered using atexit.register() to install your
cleanup routine?

richard

unread,
Jan 3, 2008, 8:31:09 AM1/3/08
to nose-users
atexit occurs too late. I now use a signal handler based on SIGINT
quite successfully.


Thanks ...

Richard


On Jan 2, 7:11 pm, "Kumar McMillan" <kumar.mcmil...@gmail.com> wrote:
Reply all
Reply to author
Forward
0 new messages