[Twisted-Python] Twisted debugging support

So, I propose to make the following change. I see no reason to destroy any hope of proper debugging support by doing a callLater of set_trace, for one. For two: control-c *really* ought to break into the debugger. Is there an actual reason why the previous code did reactor.callLater(0, pdb.set_trace)?? James Index: twisted/application/app.py =================================================================== --- twisted/application/app.py (revision 11112) +++ twisted/application/app.py (working copy) @@ -84,7 +84,8 @@ sys.stdout = oldstdout sys.stderr = oldstderr if runtime.platformType == 'posix': - signal.signal(signal.SIGUSR2, lambda *args: reactor.callLater(0, pdb.set_trace)) + signal.signal(signal.SIGUSR2, lambda *args: pdb.set_trace()) + signal.signal(signal.SIGINT, lambda *args: pdb.set_trace()) pdb.runcall(reactor.run) else: reactor.run() Index: twisted/internet/default.py =================================================================== --- twisted/internet/default.py (revision 11112) +++ twisted/internet/default.py (working copy) @@ -90,7 +90,9 @@ def _handleSignals(self): """Install the signal handlers for the Twisted event loop.""" import signal - signal.signal(signal.SIGINT, self.sigInt) + if signal.getsignal(signal.SIGINT) == signal.default_int_handler: + # only handle if there isn't already a handler, e.g. for Pdb. + signal.signal(signal.SIGINT, self.sigInt) signal.signal(signal.SIGTERM, self.sigTerm) # Catch Ctrl-Break in windows (only available in Python 2.2 and up)

On Wed, 2004-07-28 at 15:48, James Y Knight wrote:
Is there an actual reason why the previous code did reactor.callLater(0, pdb.set_trace)??
Yes, cause then pdb gets started inside the signal handler, which is in between byte codes and not anywhere useful... -- Itamar Shtull-Trauring http://itamarst.org

On Wed, 2004-07-28 at 17:00, Itamar Shtull-Trauring wrote:
Yes, cause then pdb gets started inside the signal handler, which is in between byte codes and not anywhere useful...
Actually that may be nonsense. Try and see I guess. -- Itamar Shtull-Trauring http://itamarst.org

Itamar Shtull-Trauring wrote:
On Wed, 2004-07-28 at 17:00, Itamar Shtull-Trauring wrote:
Yes, cause then pdb gets started inside the signal handler, which is in between byte codes and not anywhere useful...
Actually that may be nonsense. Try and see I guess.
Python handles the signal, waits until execution is about to proceed normally (that is, non-re-entrantly), and then calls the signal handler one has registered. The only problem I can see with removing the callLater() and switching to a SIGINT handler is that it makes quiting the application somewhat difficult. If this can be resolved, I'm in favor of the change. Jp

On Wed, 2004-07-28 at 19:21, Jp Calderone wrote:
callLater() and switching to a SIGINT handler is that it makes quiting the application somewhat difficult. If this can be resolved, I'm in favor of the change.
Switch to regular twisted SIGINT handler right before pdb.set_trace() and back to pdb handler after pdb is done? Hm, no. How about Ctrl-C and then "from twisted.internet import reactor; reactor.stop()" and then telling pdb to continue? ;)
participants (3)
-
Itamar Shtull-Trauring
-
James Y Knight
-
Jp Calderone