diff --git a/artiq/protocols/pc_rpc.py b/artiq/protocols/pc_rpc.py index 36e7e4851..735dcd9fb 100644 --- a/artiq/protocols/pc_rpc.py +++ b/artiq/protocols/pc_rpc.py @@ -490,6 +490,8 @@ class Server(_AsyncioServer): else: method = getattr(target, obj["name"]) ret = method(*obj["args"], **obj["kwargs"]) + if inspect.iscoroutine(ret): + ret = await ret obj = {"status": "ok", "ret": ret} else: raise ValueError("Unknown action: {}" diff --git a/artiq/test/pc_rpc.py b/artiq/test/pc_rpc.py index 423b4f31d..370b21188 100644 --- a/artiq/test/pc_rpc.py +++ b/artiq/test/pc_rpc.py @@ -43,6 +43,8 @@ class RPCCase(unittest.TestCase): try: test_object_back = remote.echo(test_object) self.assertEqual(test_object, test_object_back) + test_object_back = remote.async_echo(test_object) + self.assertEqual(test_object, test_object_back) with self.assertRaises(pc_rpc.RemoteError): remote.non_existing_method() remote.terminate() @@ -68,6 +70,8 @@ class RPCCase(unittest.TestCase): try: test_object_back = await remote.echo(test_object) self.assertEqual(test_object, test_object_back) + test_object_back = await remote.async_echo(test_object) + self.assertEqual(test_object, test_object_back) with self.assertRaises(pc_rpc.RemoteError): await remote.non_existing_method() await remote.terminate() @@ -105,6 +109,10 @@ class Echo: def echo(self, x): return x + async def async_echo(self, x): + await asyncio.sleep(0.01) + return x + def run_server(): loop = asyncio.new_event_loop()