Skip to content

Commit b33b29a

Browse files
committed
core: remove dead Router.on_shutdown() and Router "shutdown" signal
Its functionality was duplicated by _on_broker_exit() somewhere along the way, and nothing has referred to it in a long time. I have no idea how this happened. Merge its docstring into _on_broker_exit() and delete it, remove the Router "shutdown" signal after confirming it has no users, and move all the Router-originated error messages together in a block at the top of the class. Already covered by router_test.AddHandlerTest.test_dead_message_sent_at_shutdown
1 parent c0d87c0 commit b33b29a

File tree

2 files changed

+17
-29
lines changed

2 files changed

+17
-29
lines changed

docs/signals.rst

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,6 @@ These signals are used internally by Mitogen.
4747
- ``disconnect``
4848
- Fired on the Broker thread during shutdown (???)
4949

50-
* - :py:class:`mitogen.core.Router`
51-
- ``shutdown``
52-
- Fired on the Broker thread after Broker.shutdown() is called.
53-
5450
* - :py:class:`mitogen.core.Broker`
5551
- ``shutdown``
5652
- Fired after Broker.shutdown() is called.

mitogen/core.py

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2759,6 +2759,18 @@ class Router(object):
27592759
#: parameter.
27602760
unidirectional = False
27612761

2762+
duplicate_handle_msg = 'cannot register a handle that already exists'
2763+
refused_msg = 'refused by policy'
2764+
invalid_handle_msg = 'invalid handle'
2765+
too_large_msg = 'message too large (max %d bytes)'
2766+
respondent_disconnect_msg = 'the respondent Context has disconnected'
2767+
broker_exit_msg = 'Broker has exitted'
2768+
no_route_msg = 'no route to %r, my ID is %r'
2769+
unidirectional_msg = (
2770+
'routing mode prevents forward of message from context %d via '
2771+
'context %d'
2772+
)
2773+
27622774
def __init__(self, broker):
27632775
self.broker = broker
27642776
listen(broker, 'exit', self._on_broker_exit)
@@ -2826,9 +2838,12 @@ def _on_stream_disconnect(self, stream):
28262838
for context in notify:
28272839
context.on_disconnect()
28282840

2829-
broker_exit_msg = 'Broker has exitted'
2830-
28312841
def _on_broker_exit(self):
2842+
"""
2843+
Called prior to broker exit, informs callbacks registered with
2844+
:meth:`add_handler` the connection is dead.
2845+
"""
2846+
_v and LOG.debug('%r: broker has exitted', self)
28322847
while self._handle_map:
28332848
_, (_, func, _, _) = self._handle_map.popitem()
28342849
func(Message.dead(self.broker_exit_msg))
@@ -3006,35 +3021,12 @@ def add_handler(self, fn, handle=None, persist=True,
30063021

30073022
return handle
30083023

3009-
duplicate_handle_msg = 'cannot register a handle that already exists'
3010-
refused_msg = 'refused by policy'
3011-
invalid_handle_msg = 'invalid handle'
3012-
too_large_msg = 'message too large (max %d bytes)'
3013-
respondent_disconnect_msg = 'the respondent Context has disconnected'
3014-
broker_shutdown_msg = 'Broker is shutting down'
3015-
no_route_msg = 'no route to %r, my ID is %r'
3016-
unidirectional_msg = (
3017-
'routing mode prevents forward of message from context %d via '
3018-
'context %d'
3019-
)
3020-
30213024
def _on_respondent_disconnect(self, context):
30223025
for handle in self._handles_by_respondent.pop(context, ()):
30233026
_, fn, _, _ = self._handle_map[handle]
30243027
fn(Message.dead(self.respondent_disconnect_msg))
30253028
del self._handle_map[handle]
30263029

3027-
def on_shutdown(self, broker):
3028-
"""
3029-
Called during :meth:`Broker.shutdown`, informs callbacks registered
3030-
with :meth:`add_handler` the connection is dead.
3031-
"""
3032-
_v and LOG.debug('%r: shutting down', self, broker)
3033-
fire(self, 'shutdown')
3034-
for handle, (persist, fn) in self._handle_map.iteritems():
3035-
_v and LOG.debug('%r.on_shutdown(): killing %r: %r', self, handle, fn)
3036-
fn(Message.dead(self.broker_shutdown_msg))
3037-
30383030
def _maybe_send_dead(self, msg, reason, *args):
30393031
if args:
30403032
reason %= args

0 commit comments

Comments
 (0)