Skip to content
This repository

Don't crash when debugging threaded app. #29

Merged
merged 1 commit into from over 2 years ago

2 participants

P. Varet Andreas Klöckner
P. Varet

Due to urwid's use of signals, running PuDB from a thread other than the main thread -- which happens systematically when trying to debug a Zope view -- would cause PuDB to crash.

This patch fixes the issue by allowing the signal installation and restore calls to fail gracefully.

Andreas Klöckner inducer merged commit 8d0a9a4 into from January 04, 2012
Andreas Klöckner inducer closed this January 04, 2012
Andreas Klöckner
Owner

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Jan 04, 2012
P. Varet Don't crash when running PuDB from a non-main thread. 7d9226d
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 19 additions and 3 deletions. Show diff stats Hide diff stats

  1. 22  pudb/debugger.py
22  pudb/debugger.py
@@ -290,6 +290,24 @@ def _runscript(self, filename):
290 290
 from pudb.var_view import FrameVarInfoKeeper
291 291
 
292 292
 
  293
+from urwid.raw_display import Screen
  294
+
  295
+class ThreadsafeScreen(Screen):
  296
+    "A Screen subclass that doesn't crash when running from a non-main thread."
  297
+
  298
+    def signal_init(self):
  299
+        "Initialize signal handler, ignoring errors silently."
  300
+        try:
  301
+            super(ThreadsafeScreen, self).signal_init()
  302
+        except ValueError:
  303
+            pass
  304
+
  305
+    def signal_restore(self):
  306
+        "Restore default signal handler, ignoring errors silently."
  307
+        try:
  308
+            super(ThreadsafeScreen, self).signal_restore()
  309
+        except ValueError:
  310
+            pass
293 311
 
294 312
 
295 313
 class DebuggerUI(FrameVarInfoKeeper):
@@ -1097,9 +1115,7 @@ def help(w, size, key):
1097 1115
 
1098 1116
         # {{{ setup
1099 1117
 
1100  
-        import urwid.raw_display as display
1101  
-
1102  
-        self.screen = display.Screen()
  1118
+        self.screen = ThreadsafeScreen()
1103 1119
         self.setup_palette(self.screen)
1104 1120
 
1105 1121
         self.show_count = 0
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.