[Twisted-Python] Twisted debugging support
![](https://secure.gravatar.com/avatar/15fa47f2847592672210af8a25cd1f34.jpg?s=120&d=mm&r=g)
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)
![](https://secure.gravatar.com/avatar/d7875f8cfd8ba9262bfff2bf6f6f9b35.jpg?s=120&d=mm&r=g)
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
![](https://secure.gravatar.com/avatar/d7875f8cfd8ba9262bfff2bf6f6f9b35.jpg?s=120&d=mm&r=g)
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
![](https://secure.gravatar.com/avatar/7ed9784cbb1ba1ef75454034b3a8e6a1.jpg?s=120&d=mm&r=g)
Itamar Shtull-Trauring wrote:
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
![](https://secure.gravatar.com/avatar/d7875f8cfd8ba9262bfff2bf6f6f9b35.jpg?s=120&d=mm&r=g)
On Wed, 2004-07-28 at 19:21, Jp Calderone wrote:
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? ;)
![](https://secure.gravatar.com/avatar/d7875f8cfd8ba9262bfff2bf6f6f9b35.jpg?s=120&d=mm&r=g)
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
![](https://secure.gravatar.com/avatar/d7875f8cfd8ba9262bfff2bf6f6f9b35.jpg?s=120&d=mm&r=g)
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
![](https://secure.gravatar.com/avatar/7ed9784cbb1ba1ef75454034b3a8e6a1.jpg?s=120&d=mm&r=g)
Itamar Shtull-Trauring wrote:
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
![](https://secure.gravatar.com/avatar/d7875f8cfd8ba9262bfff2bf6f6f9b35.jpg?s=120&d=mm&r=g)
On Wed, 2004-07-28 at 19:21, Jp Calderone wrote:
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