From 2973d7f1de4922a051f03a7dd978cb94f57284a3 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Fri, 21 Sep 2018 00:31:30 -0400 Subject: [PATCH] Await async funcs properly in `LocalPortal.run()` --- tractor/_actor.py | 2 +- tractor/_portal.py | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/tractor/_actor.py b/tractor/_actor.py index c9daa81..2e08b12 100644 --- a/tractor/_actor.py +++ b/tractor/_actor.py @@ -768,7 +768,7 @@ async def wait_for_actor( ) -> typing.AsyncGenerator[Portal, None]: """Wait on an actor to register with the arbiter. - A portal to the first actor which registered is be returned. + A portal to the first registered actor is returned. """ actor = current_actor() async with get_arbiter(*arbiter_sockaddr or actor._arb_addr) as arb_portal: diff --git a/tractor/_portal.py b/tractor/_portal.py index f8a01ac..6eaab31 100644 --- a/tractor/_portal.py +++ b/tractor/_portal.py @@ -2,6 +2,7 @@ Portal api """ import importlib +import inspect import typing from typing import Tuple, Any, Dict, Optional @@ -220,7 +221,11 @@ class LocalPortal: """Run a requested function locally and return it's result. """ obj = self.actor if ns == 'self' else importlib.import_module(ns) - return getattr(obj, func)(**kwargs) + func = getattr(obj, func) + if inspect.iscoroutinefunction(func): + return await func(**kwargs) + else: + return func(**kwargs) @asynccontextmanager