def wrap(f): f = trollius.coroutine(f) @functools.wraps(f) def wrapper(self): return self.event_loop.run_until_complete( trollius.wait_for(f(self), timeout=timeout, loop=self.event_loop) ) return wrapper
def call_as_future(callable, loop, *args, **kwargs): """This is a copy of thrift.util.asyncio. So, let's consider unifying them. call_as_future(callable, *args, **kwargs) -> trollius.Task Like trollius.ensure_future() but takes any callable and converts it to a coroutine function first. """ if not asyncio.iscoroutinefunction(callable): callable = asyncio.coroutine(callable) return asyncio.ensure_future(callable(*args, **kwargs), loop=loop)
def call_as_future(callable, *args, **kwargs): """This is a copy of thrift.util.asyncio. So, let's consider unifying them. call_as_future(callable, *args, **kwargs) -> trollius.Task Like trollius.ensure_future() but takes any callable and converts it to a coroutine function first. """ if not asyncio.iscoroutinefunction(callable): callable = asyncio.coroutine(callable) return asyncio.ensure_future(callable(*args, **kwargs))
def wrapper(*args, **kwargs): coro = asyncio.coroutine(f) future = coro(*args, **kwargs) testLoop.run_until_complete(future)
def wrapper(*args, **kwargs): coro = coroutine(f) future = coro(*args, **kwargs) loop = get_event_loop() loop.run_until_complete(future)
def wrapper(*args, **kwargs): f = fn if asyncio.iscoroutinefunction(fn) else asyncio.coroutine(fn) loop.run_until_complete(f(*args, **kwargs))
def on_closed(*args): global dropbot dropbot = None signals = blinker.Namespace() signals.signal('version-mismatch').connect(on_version_mismatch, weak=False) signals.signal('no-power').connect(on_no_power, weak=False) signals.signal('connected').connect(on_connected, weak=False) signals.signal('disconnected').connect(on_disconnected, weak=False) for name_i in DROPBOT_SIGNAL_NAMES + ('chip-inserted', 'chip-removed'): if name_i in ('output_enabled', 'output_disabled'): continue elif name_i == 'capacitance-updated': task = ft.partial(asyncio.coroutine(debounced_dump), name_i) signals.signal(name_i).connect(task, weak=False) else: signals.signal(name_i).connect(ft.partial(co_dump, name_i), weak=False) signals.signal('closed').connect(on_closed, weak=False) if platform.system() == 'Windows': loop = asyncio.ProactorEventLoop() asyncio.set_event_loop(loop) else: loop = asyncio.get_event_loop() task = loop.create_task(monitor(signals)) loop.run_until_complete(task)