##// END OF EJS Templates
Make event triggering robust to (un)registration....
Craig Citro -
r22317:68860ee5
parent child
Show More
@@ -0,0 +1,7
1 Update IPython event triggering to ensure callback registration and
2 unregistration only affects the set of callbacks the *next* time that event is
3 triggered. See :ghissue:`9447` and :ghpull:`9453`.
4
5 This is a change to the existing semantics, wherein one callback registering a
6 second callback when triggered for an event would previously be invoked for
7 that same event.
@@ -69,7 +69,7 class EventManager(object):
69 Any additional arguments are passed to all callbacks registered for this
69 Any additional arguments are passed to all callbacks registered for this
70 event. Exceptions raised by callbacks are caught, and a message printed.
70 event. Exceptions raised by callbacks are caught, and a message printed.
71 """
71 """
72 for func in self.callbacks[event]:
72 for func in self.callbacks[event][:]:
73 try:
73 try:
74 func(*args, **kwargs)
74 func(*args, **kwargs)
75 except Exception:
75 except Exception:
@@ -30,3 +30,25 class CallbackTests(unittest.TestCase):
30 self.em.register('ping_received', cb)
30 self.em.register('ping_received', cb)
31 with tt.AssertPrints("Error in callback"):
31 with tt.AssertPrints("Error in callback"):
32 self.em.trigger('ping_received')
32 self.em.trigger('ping_received')
33
34 def test_unregister_during_callback(self):
35 invoked = [False] * 3
36
37 def func1(*_):
38 invoked[0] = True
39 self.em.unregister('ping_received', func1)
40 self.em.register('ping_received', func3)
41
42 def func2(*_):
43 invoked[1] = True
44 self.em.unregister('ping_received', func2)
45
46 def func3(*_):
47 invoked[2] = True
48
49 self.em.register('ping_received', func1)
50 self.em.register('ping_received', func2)
51
52 self.em.trigger('ping_received')
53 self.assertEqual([True, True, False], invoked)
54 self.assertEqual([func3], self.em.callbacks['ping_received'])
General Comments 0
You need to be logged in to leave comments. Login now