Permalink
Browse files

I forgot to destroy all the timers and pollers when we destroy the lo…

…op...
  • Loading branch information...
1 parent 604dc1c commit b6b8c7e62b715f28740a3aea4fe0ff8fc41285e5 Alvaro committed Nov 19, 2012
Showing with 27 additions and 10 deletions.
  1. +27 −10 evy/hubs/hub.py
View
@@ -341,7 +341,11 @@ def run (self, *a, **kw):
if self.num_active == 0:
self.stopping = True
else:
+ ## remove all the timers and pollers
+ for timer in self.timers: timer.destroy()
+ for poller in self.pollers.values(): poller.destroy()
self.timers = set()
+ self.pollers = {}
finally:
self.running = False
@@ -384,6 +388,13 @@ def destroy(self):
"""
global _default_loop_destroyed
if self._uv_ptr:
+
+ ## destroy all the timers and pollers
+ for timer in self.timers: timer.destroy()
+ for poller in self.pollers.values(): poller.destroy()
+ self.timers = set()
+ self.pollers = {}
+
self._stop_signal_checker()
#if __SYSERR_CALLBACK == self._handle_syserr:
# set_syserr_cb(None)
@@ -392,6 +403,8 @@ def destroy(self):
libuv.uv_loop_destroy(self._uv_ptr)
self._uv_ptr = ffi.NULL
+
+
@property
def num_active(self):
return self._uv_ptr.active_handles
@@ -445,15 +458,19 @@ def _timer_triggered (self, timer):
timer()
except self.SYSTEM_EXCEPTIONS:
self.interrupted = True
- except:
- self.squelch_exception(-1, sys.exc_info())
+ except Exception, e:
+ self.squelch_timer_exception(timer, sys.exc_info())
try:
timer.destroy()
- self.timers.remove(timer)
except (AttributeError, TypeError):
pass
+ try:
+ self.timers.remove(timer)
+ except KeyError:
+ pass
+
def forget_timer(self, timer):
"""
Let the hub forget about a timer, so we do not keep the loop running forever until
@@ -700,13 +717,13 @@ def squelch_generic_exception (self, exc_info):
def squelch_exception (self, fileno, exc_info):
traceback.print_exception(*exc_info)
- sys.stderr.write("Removing descriptor: %r\n" % (fileno,))
- sys.stderr.flush()
- try:
- self.remove_descriptor(fileno)
- except Exception, e:
- sys.stderr.write("Exception while removing descriptor! %r\n" % (e,))
- sys.stderr.flush()
+
+ if fileno > 0:
+ try:
+ self.remove_descriptor(fileno)
+ except Exception, e:
+ sys.stderr.write("Exception while removing descriptor! %r\n" % (e,))
+ sys.stderr.flush()
def squelch_timer_exception (self, timer, exc_info):
if self.debug_exceptions:

0 comments on commit b6b8c7e

Please sign in to comment.