From: Kevin Pouget <kevin.pouget@gmail.com>
To: Paul_Koning@dell.com, khooyp@cs.umd.edu
Cc: tromey@redhat.com, gdb-patches@sourceware.org, dje@google.com
Subject: Re: Handle SIGINT in Python
Date: Fri, 13 Jan 2012 10:55:00 -0000 [thread overview]
Message-ID: <CAPftXUKSb6ndq0jXLgFpSgUU5Tgiq0FLbR=nMnuhv610K8dcMA@mail.gmail.com> (raw)
In-Reply-To: <09787EF419216C41A903FD14EE5506DD030F1EB37E@AUSX7MCPC103.AMER.DELL.COM>
On Thu, Jan 12, 2012 at 5:47 PM, <Paul_Koning@dell.com> wrote:
>>just my 2 cents to the discussion.
>>[I'm not sure I could follow all the arguments, so my comments are based on Khoo's patch]
>>
>>+static void
>>+gdbpy_handle_sigint (int sig)
>>+{
>>+ PyErr_SetInterrupt ();
>>+}
>>
>
> The only difference is in what happens when you get to the top of a Python script with a KeyboardInterrupt exception and no one is catching it. In an interactive session (python shell) you get a backtrace. I think in a Python interactive session inside GDB ("python" command with no arguments) the same should be true. In a script invocation from the command shell (outside GDB) you'd also get a traceback in this case. In GDB, you probably should not, as was discussed earlier; in that case, the interrupt should be passed up to the GDB common machinery to handle exactly as it would handle an interrupt for any other command, without a Python style traceback printout.
On Thu, Jan 12, 2012 at 4:35 PM, Khoo Yit Phang <khooyp@cs.umd.edu> wrote:
> Your concern does not arise: PyErr_SetInterrupt does not raise any exception, it simply sets a flag which Python checks every now and then in the
> interpreter loop. The same thing happens for any Python exception that is raised in C: you would set an exception via PyErr_SetString(exception,
> message) or similar, and return NULL or -1 to the interpreter.
Thanks for the clarifications, but I'm still not unsure about how to
build a reliable application on top of GDB with this kind of SIGINT
handling.
I'm not an expert on Python programming nor on 'reliable application
design' (and I'm used to C programming) so please bear with me if
there are some flaws in my arguments, I'm just trying to figure out
how this patch would influence my code:)
> Any Python statement can throw a KeyboardException.
That could make sense in a stateless / lightweight application, but in
[my] GDB-base Python application, I can't see how this can remain the
default behavior ... I'm a bit stuck with the FLAG handling I
described in the previous mail, 1 C^c sets a flag, 2 C^c raises an
exception (and almost kills the app), but I can't see any other way to
safely handle this SIGINT.
(or I can implement the flag mechanism by myself, as in
http://stackoverflow.com/a/4205386/341106:
> import signal
> def signal_handler(signal, frame):
> print 'You pressed Ctrl+C!'
> # what ever ...
> signal.signal(signal.SIGINT, signal_handler)
but I guess I would still have to surround GDB function calls with
KeyboardInterrupt handling ...)
Cordially,
Kevin
next prev parent reply other threads:[~2012-01-13 9:05 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-10 21:31 Khoo Yit Phang
2012-01-10 21:47 ` Doug Evans
2012-01-10 22:09 ` Khoo Yit Phang
2012-01-11 20:59 ` Tom Tromey
2012-01-11 21:06 ` Paul_Koning
2012-01-11 21:23 ` Tom Tromey
2012-01-12 0:54 ` Doug Evans
2012-01-12 15:52 ` Kevin Pouget
2012-01-12 16:48 ` Paul_Koning
2012-01-13 10:55 ` Kevin Pouget [this message]
2012-01-13 12:11 ` Paul_Koning
2012-01-10 21:49 ` Tom Tromey
2012-01-11 21:15 ` Tom Tromey
2012-01-11 21:49 ` Khoo Yit Phang
2012-01-11 22:46 ` Khoo Yit Phang
2012-01-20 21:40 ` Tom Tromey
2012-01-22 16:36 ` Khoo Yit Phang
2012-01-22 20:54 ` Khoo Yit Phang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAPftXUKSb6ndq0jXLgFpSgUU5Tgiq0FLbR=nMnuhv610K8dcMA@mail.gmail.com' \
--to=kevin.pouget@gmail.com \
--cc=Paul_Koning@dell.com \
--cc=dje@google.com \
--cc=gdb-patches@sourceware.org \
--cc=khooyp@cs.umd.edu \
--cc=tromey@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox