Description
#367 changed the initialisation of the task in ApplicationCommunicator
from using asyncio.ensure_future
to using asyncio.create_task
While is is generally a positive change and use of asyncio.create_task
is generally preferred over low-level primitives like asyncio.ensure_future
this has the side effect that, since asyncio.create_task
uses asyncio.get_running_loop
under the hood where asyncio.ensure_future
used asyncio.get_event_loop
, an ApplicationCommunicator
can no longer be constructed outside of a coroutine or callback
In my test suite I'm using unittest
with synchronous test functions and I have code to explicitly manage event loops and configure them for use using asyncio.set_event_loop
I've been able to workaround this using code like the following:
def _task():
return ApplicationCommunicator(*args, **kwargs)
task = loop.create_task(_task())
while not task.done():
pass
return task.result()
I wonder if this code could, instead, be calling asyncio.get_event_loop
and calling loop.create_task
instead of asyncio.create_task
so that it works correctly in a synchronous context with an assigned event loop.