Esempio n. 1
0
 def async_test(*args, **kw):
     exc_info = None
     try:
         if iscoroutinefunction(func):
             exc_info = get_kernel().run(run_test_async, args, kw)
         else:
             func(*args, **kw)
     finally:
         close_kernel()
     if exc_info:
         raise exc_info[0].with_traceback(exc_info[1], exc_info[2])
Esempio n. 2
0
 async def _handle_ack(self, acked_sequence):
     self._update_latency(time.time() - self._pending_acks[acked_sequence])
     if acked_sequence in self._events_with_callbacks:
         for event_sequence in self._events_with_callbacks[acked_sequence]:
             if self._event_callbacks[event_sequence]["ack"] is not None:
                 if iscoroutinefunction(
                         self._event_callbacks[event_sequence]["ack"]):
                     await self._event_callbacks[event_sequence]["ack"]()
                 else:
                     self._event_callbacks[event_sequence]["ack"]()
                 del self._event_callbacks[event_sequence]
         del self._events_with_callbacks[acked_sequence]
     del self._pending_acks[acked_sequence]
Esempio n. 3
0
 async def _handle_timeout(self, timed_out_sequence):
     if timed_out_sequence in self._events_with_callbacks:
         for event_sequence in self._events_with_callbacks[
                 timed_out_sequence]:
             if self._event_callbacks[event_sequence][
                     "timeout"] is not None:
                 if iscoroutinefunction(
                         self._event_callbacks[event_sequence]["timeout"]):
                     await self._event_callbacks[event_sequence]["timeout"](
                     )
                 else:
                     self._event_callbacks[event_sequence]["timeout"]()
                 del self._event_callbacks[event_sequence]
         del self._events_with_callbacks[timed_out_sequence]
     del self._pending_acks[timed_out_sequence]
Esempio n. 4
0
    async def handle(self, event: Event, **kwargs):
        """Asynchronously invoke the appropriate handler function.

        This method is a coroutine and must be `await`ed.

        # Arguments
        event (Event): the event to be handled

        keyword arguments to be passed to the handler function (in addition to those already attached to the event)

        """
        logger.debug((
            f"Handling {event.type} event with args={event.handler_args} and kwargs={event.handler_kwargs}."
        ))
        if iscoroutinefunction(self._event_handlers[event.type]):
            return await self._event_handlers[event.type
                                              ](*event.handler_args,
                                                **dict(event.handler_kwargs,
                                                       **kwargs))
        return self._event_handlers[event.type](*event.handler_args,
                                                **dict(event.handler_kwargs,
                                                       **kwargs))
Esempio n. 5
0
def test_iscoroutinefunc():
    async def spam(x, y):
        pass

    assert meta.iscoroutinefunction(partial(spam, 1))
Esempio n. 6
0
def _is_coroutine(obj):
    """Check to see if an object is really a coroutine."""
    return meta.iscoroutinefunction(obj) or inspect.isgeneratorfunction(obj)
Esempio n. 7
0
def test_iscoroutinefunc():
    async def spam(x, y):
        pass

    assert meta.iscoroutinefunction(partial(spam, 1))