From 905b76c74d7220cbad04e5aa7b2e958113afc626 Mon Sep 17 00:00:00 2001 From: Jusong Yu Date: Mon, 30 Dec 2024 01:14:52 +0100 Subject: [PATCH] Simpler create_task_threadsafe implementation --- src/plumpy/futures.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/plumpy/futures.py b/src/plumpy/futures.py index f3e8a30b..b67c0e80 100644 --- a/src/plumpy/futures.py +++ b/src/plumpy/futures.py @@ -78,12 +78,16 @@ def create_task(coro: Callable[[], Awaitable[Any]], loop: Optional[asyncio.Abstr """ loop = loop or asyncio.get_event_loop() - future = loop.create_future() - - async def run_task() -> None: - with capture_exceptions(future): - res = await coro() - future.set_result(res) - - asyncio.run_coroutine_threadsafe(run_task(), loop) - return future + # future = loop.create_future() + # + # async def run_task() -> None: + # with capture_exceptions(future): + # res = await coro() + # future.set_result(res) + # + # asyncio.run_coroutine_threadsafe(run_task(), loop) + # return future + + return asyncio.wrap_future( + asyncio.run_coroutine_threadsafe(coro(), loop) + )