Skip to content

Commit

Permalink
Simpler create_task_threadsafe implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
unkcpz committed Dec 30, 2024
1 parent c016068 commit 803bc15
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/plumpy/futures.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)

0 comments on commit 803bc15

Please sign in to comment.