def done_callback(yielded): # To be called when a future dependency has completed. Advance the # tasklet with the yielded value or error. # # It was tempting to call `_advance_tasklet` (`_help_tasklet_along` # in Legacy) directly. Doing so, it has been found, can lead to # exceeding the maximum recursion depth. Queing it up to run on the # event loop avoids this issue by keeping the call stack shallow. error = yielded.exception() if error: _eventloop.call_soon(self._advance_tasklet, error=error) else: _eventloop.call_soon(self._advance_tasklet, yielded.result())
def test_context_unfinished_business(): """Regression test for #213. Make sure the eventloop is exhausted inside the context. https://github.com/googleapis/python-ndb/issues/213 """ with patch_credentials("testing"): client = client_module.Client() def finish_up(): context = context_module.get_context() assert context.client is client with client.context(): _eventloop.call_soon(finish_up)
def test_call_soon(context): loop = mock.Mock(spec=("run", "call_soon")) with context.new(eventloop=loop).use(): _eventloop.call_soon("foo", "bar", baz="qux") loop.call_soon.assert_called_once_with("foo", "bar", baz="qux")