def wait_all(cls, futures):

        waiting_on = set(futures)
        ev = eventloop.get_event_loop()
        while waiting_on:
            waiting_on = set(f for f in waiting_on if f.state == cls.RUNNING)
            ev.run1()
    def wait_any(cls, futures):

        waiting_on = set(futures)
        ev = eventloop.get_event_loop()
        while waiting_on:
            for f in waiting_on:
                if f.state == cls.FINISHING:
                    return f
            ev.run1()
        return None
Exemple #3
0
 def tearDown(self):
   """Tear down test framework."""
   self._logger.setLevel(self._old_log_level)
   ev = eventloop.get_event_loop()
   stragglers = 0
   while ev.run1():
     stragglers += 1
   if stragglers:
     logging.info('Processed %d straggler events after test completed',
                  stragglers)
   self.ResetKindMap()
   self.testbed.deactivate()
Exemple #4
0
 def tearDown(self):
     """Tear down test framework."""
     self._logger.setLevel(self._old_log_level)
     ev = eventloop.get_event_loop()
     stragglers = 0
     while ev.run1():
         stragglers += 1
     if stragglers:
         logging.info('Processed %d straggler events after test completed',
                      stragglers)
     self.ResetKindMap()
     self.testbed.deactivate()
 def wait(self):
     if self._done:
         return
     ev = eventloop.get_event_loop()
     while not self._done:
         if not ev.run1():
             logging.info('Deadlock in %s', self)
             logging.info('All pending Futures:\n%s',
                          _state.dump_all_pending())
             _logging_debug('All pending Futures (verbose):\n%s',
                            _state.dump_all_pending(verbose=True))
             self.set_exception(
                 RuntimeError('Deadlock waiting for %s' % self))
def _run_until_rpc():
  """Eagerly evaluate tasklets until it is blocking on some RPC.

  Usually ndb eventloop el isn't run until some code calls future.get_result().

  When an async tasklet is called, the tasklet wrapper evaluates the tasklet
  code into a generator, enqueues a callback _help_tasklet_along onto
  the el.current queue, and returns a future.

  _help_tasklet_along, when called by the el, will
  get one yielded value from the generator. If the value if another future,
  set up a callback _on_future_complete to invoke _help_tasklet_along
  when the dependent future fulfills. If the value if a RPC, set up a
  callback _on_rpc_complete to invoke _help_tasklet_along when the RPC fulfills.
  Thus _help_tasklet_along drills down
  the chain of futures until some future is blocked by RPC. El runs
  all callbacks and constantly check pending RPC status.
  """
  el = eventloop.get_event_loop()
  while el.current:
    el.run0()
Exemple #7
0
def _run_until_rpc():
    """Eagerly evaluate tasklets until it is blocking on some RPC.

  Usually ndb eventloop el isn't run until some code calls future.get_result().

  When an async tasklet is called, the tasklet wrapper evaluates the tasklet
  code into a generator, enqueues a callback _help_tasklet_along onto
  the el.current queue, and returns a future.

  _help_tasklet_along, when called by the el, will
  get one yielded value from the generator. If the value if another future,
  set up a callback _on_future_complete to invoke _help_tasklet_along
  when the dependent future fulfills. If the value if a RPC, set up a
  callback _on_rpc_complete to invoke _help_tasklet_along when the RPC fulfills.
  Thus _help_tasklet_along drills down
  the chain of futures until some future is blocked by RPC. El runs
  all callbacks and constantly check pending RPC status.
  """
    el = eventloop.get_event_loop()
    while el.current:
        el.run0()
 def reset(self, unused_req_id):
     self.current_context = None
     ev = eventloop.get_event_loop()
     ev.clear()
     self.clear_all_pending()
     self.clear_all_generators()