From 9e78c20ebaa04dd62b798377dfbbf7d271c045d4 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Sat, 9 Jun 2018 21:01:58 +0100 Subject: [PATCH] core/parent: add Context.call_no_reply(). --- docs/api.rst | 10 +++++++++- mitogen/core.py | 8 ++++++-- mitogen/parent.py | 5 +++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/docs/api.rst b/docs/api.rst index 20389180..114f58d0 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -857,7 +857,7 @@ Context Class .. method:: call (fn, \*args, \*\*kwargs) - Equivalent to :py:meth:`call_async(fn, \*args, \**kwargs).get_data() + Equivalent to :py:meth:`call_async(fn, \*args, \**kwargs).get().unpickle() `. :returns: @@ -866,6 +866,14 @@ Context Class :raises mitogen.core.CallError: An exception was raised in the remote context during execution. + .. method:: call_no_reply (fn, \*args, \*\*kwargs) + + Send a function call, but expect no return value. If the call fails, + the full exception will be logged to the target context's logging framework. + + :raises mitogen.core.CallError: + An exception was raised in the remote context during execution. + Receiver Class diff --git a/mitogen/core.py b/mitogen/core.py index 023b68ca..3ce3d97a 100644 --- a/mitogen/core.py +++ b/mitogen/core.py @@ -1857,12 +1857,16 @@ class ExternalContext(object): for msg in self.recv: try: ret = self._dispatch_one(msg) + _v and LOG.debug('_dispatch_calls: %r -> %r', msg, ret) if msg.reply_to: msg.reply(ret) except Exception: e = sys.exc_info()[1] - _v and LOG.debug('_dispatch_calls: %s', e) - msg.reply(CallError(e)) + if msg.reply_to: + _v and LOG.debug('_dispatch_calls: %s', e) + msg.reply(CallError(e)) + else: + LOG.exception('_dispatch_calls: %r', msg) self.dispatch_stopped = True def main(self): diff --git a/mitogen/parent.py b/mitogen/parent.py index 1d645f23..7e095dea 100644 --- a/mitogen/parent.py +++ b/mitogen/parent.py @@ -912,6 +912,11 @@ class Context(mitogen.core.Context): receiver = self.call_async(fn, *args, **kwargs) return receiver.get().unpickle(throw_dead=False) + def call_no_reply(self, fn, *args, **kwargs): + LOG.debug('%r.call_no_reply(%r, *%r, **%r)', + self, fn, args, kwargs) + self.send(make_call_msg(fn, *args, **kwargs)) + def shutdown(self, wait=False): LOG.debug('%r.shutdown() sending SHUTDOWN', self) latch = mitogen.core.Latch()