@@ -112,35 +112,38 @@ def buildProtocol(self, addr):
112112 return EvalProtocol (self .repl )
113113
114114
115- class TwistedEventLoop (urwid .TwistedEventLoop ):
116-
117- """TwistedEventLoop modified to properly stop the reactor.
118-
119- urwid 0.9.9 and 0.9.9.1 crash the reactor on ExitMainLoop instead
120- of stopping it. One obvious way this breaks is if anything used
121- the reactor's thread pool: that thread pool is not shut down if
122- the reactor is not stopped, which means python hangs on exit
123- (joining the non-daemon threadpool threads that never exit). And
124- the default resolver is the ThreadedResolver, so if we looked up
125- any names we hang on exit. That is bad enough that we hack up
126- urwid a bit here to exit properly.
127- """
115+ if urwid .VERSION < (1 , 0 , 0 ):
116+ class TwistedEventLoop (urwid .TwistedEventLoop ):
117+
118+ """TwistedEventLoop modified to properly stop the reactor.
119+
120+ urwid 0.9.9 and 0.9.9.1 crash the reactor on ExitMainLoop instead
121+ of stopping it. One obvious way this breaks is if anything used
122+ the reactor's thread pool: that thread pool is not shut down if
123+ the reactor is not stopped, which means python hangs on exit
124+ (joining the non-daemon threadpool threads that never exit). And
125+ the default resolver is the ThreadedResolver, so if we looked up
126+ any names we hang on exit. That is bad enough that we hack up
127+ urwid a bit here to exit properly.
128+ """
128129
129- def handle_exit (self , f ):
130- def wrapper (* args , ** kwargs ):
131- try :
132- return f (* args , ** kwargs )
133- except urwid .ExitMainLoop :
134- # This is our change.
135- self .reactor .stop ()
136- except :
137- # This is the same as in urwid.
138- # We are obviously not supposed to ever hit this.
139- import sys
140- print sys .exc_info ()
141- self ._exc_info = sys .exc_info ()
142- self .reactor .crash ()
143- return wrapper
130+ def handle_exit (self , f ):
131+ def wrapper (* args , ** kwargs ):
132+ try :
133+ return f (* args , ** kwargs )
134+ except urwid .ExitMainLoop :
135+ # This is our change.
136+ self .reactor .stop ()
137+ except :
138+ # This is the same as in urwid.
139+ # We are obviously not supposed to ever hit this.
140+ import sys
141+ print sys .exc_info ()
142+ self ._exc_info = sys .exc_info ()
143+ self .reactor .crash ()
144+ return wrapper
145+ else :
146+ TwistedEventLoop = urwid .TwistedEventLoop
144147
145148
146149class Statusbar (object ):
0 commit comments