From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27195 invoked by alias); 13 Jan 2012 09:05:53 -0000 Received: (qmail 27184 invoked by uid 22791); 13 Jan 2012 09:05:52 -0000 X-SWARE-Spam-Status: No, hits=-2.1 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW X-Spam-Check-By: sourceware.org Received: from mail-vx0-f169.google.com (HELO mail-vx0-f169.google.com) (209.85.220.169) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 13 Jan 2012 09:05:39 +0000 Received: by vcbf1 with SMTP id f1so209013vcb.0 for ; Fri, 13 Jan 2012 01:05:38 -0800 (PST) Received: by 10.220.213.137 with SMTP id gw9mr755704vcb.3.1326445538169; Fri, 13 Jan 2012 01:05:38 -0800 (PST) MIME-Version: 1.0 Received: by 10.220.3.130 with HTTP; Fri, 13 Jan 2012 01:05:17 -0800 (PST) In-Reply-To: <09787EF419216C41A903FD14EE5506DD030F1EB37E@AUSX7MCPC103.AMER.DELL.COM> References: <09787EF419216C41A903FD14EE5506DD030F1EB37E@AUSX7MCPC103.AMER.DELL.COM> From: Kevin Pouget Date: Fri, 13 Jan 2012 10:55:00 -0000 Message-ID: Subject: Re: Handle SIGINT in Python To: Paul_Koning@dell.com, khooyp@cs.umd.edu Cc: tromey@redhat.com, gdb-patches@sourceware.org, dje@google.com Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2012-01/txt/msg00464.txt.bz2 On Thu, Jan 12, 2012 at 5:47 PM, 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) >>+{ >>+ =A0PyErr_SetInterrupt (); >>+} >> > > The only difference is in what happens when you get to the top of a Pytho= n script with a KeyboardInterrupt exception and no one is catching it. =A0I= n an interactive session (python shell) you get a backtrace. =A0I think in = a Python interactive session inside GDB ("python" command with no arguments= ) the same should be true. =A0In a script invocation from the command shell= (outside GDB) you'd also get a traceback in this case. =A0In GDB, you prob= ably should not, as was discussed earlier; in that case, the interrupt shou= ld be passed up to the GDB common machinery to handle exactly as it would h= andle an interrupt for any other command, without a Python style traceback = printout. On Thu, Jan 12, 2012 at 4:35 PM, Khoo Yit Phang wrote: > Your concern does not arise: PyErr_SetInterrupt does not raise any except= ion, 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