From 8f85ee038e9f754e540a210894a79dab037d7244 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Wed, 12 Dec 2018 23:40:39 +0000 Subject: [PATCH] core: Add Router.self() Returns a reference to the current context. --- mitogen/core.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/mitogen/core.py b/mitogen/core.py index a55fe93a..be44c800 100644 --- a/mitogen/core.py +++ b/mitogen/core.py @@ -2154,6 +2154,16 @@ class Router(object): _, (_, func, _, _) = self._handle_map.popitem() func(Message.dead(self.broker_exit_msg)) + def self(self): + """ + Return a :class:`Context` referring to the current process. + """ + return self.context_class( + router=self, + context_id=mitogen.context_id, + name='self', + ) + def context_by_id(self, context_id, via_id=None, create=True, name=None): """ Messy factory/lookup function to find a context by its ID, or construct