parent: add Context.forget_chain().

pull/372/head
David Wilson 6 years ago
parent 37223adacd
commit a3957d6aaf

@ -934,9 +934,9 @@ Context Class
if recv.get().unpickle() == 'baz':
pass
Note that for long-lived programs, there is presently no mechanism
for clearing the chain history on a target. This will be addressed
in future.
It is necessary to explicitly clean up the chain history on a
target, otherwise unbounded memory usage is possible. See
:meth:`forget_chain`.
:returns:
:class:`mitogen.core.Receiver` configured to receive the result
@ -977,6 +977,11 @@ Context Class
:raises mitogen.core.CallError:
An exception was raised in the remote context during execution.
.. method:: forget_chain (chain_id)
Instruct the target to forget any exception related to `chain_id`, a
key previously used as the `mitogen_chain` parameter to
:meth:`call_async`.
Receiver Class

@ -1959,6 +1959,11 @@ class Dispatcher(object):
policy=has_parent_authority)
listen(econtext.broker, 'shutdown', self.recv.close)
@classmethod
@takes_econtext
def forget_chain(cls, chain_id, econtext):
econtext.dispatcher._error_by_chain_id.pop(chain_id, None)
def _parse_request(self, msg):
data = msg.unpickle(throw=False)
_v and LOG.debug('_dispatch_one(%r)', data)

@ -1160,6 +1160,9 @@ class Context(mitogen.core.Context):
self, fn, args, kwargs)
self.send(make_call_msg(fn, *args, **kwargs))
def forget_chain(self, chain_id):
self.call_no_reply(mitogen.core.Dispatcher.forget_chain, chain_id)
def shutdown(self, wait=False):
LOG.debug('%r.shutdown() sending SHUTDOWN', self)
latch = mitogen.core.Latch()

@ -143,6 +143,14 @@ class ChainTest(testlib.RouterMixin, testlib.TestCase):
lambda: self.local.call(func_returns_arg, 'yes', mitogen_chain='c1'))
self.local.call_no_reply(function_that_fails, 'c2', mitogen_chain='c2')
def test_forget(self):
self.local.call_no_reply(function_that_fails, 'x1', mitogen_chain='c1')
e1 = self.assertRaises(mitogen.core.CallError,
lambda: self.local.call(function_that_fails, 'x2', mitogen_chain='c1'))
self.local.forget_chain('c1')
self.assertEquals('x3',
self.local.call(func_returns_arg, 'x3', mitogen_chain='c1'))
if __name__ == '__main__':
unittest2.main()

Loading…
Cancel
Save