'Python asyncio run in thread causing Future error

I am running asyncio.run(func) in separate callback threads, and am receiving this error:

RuntimeError: Task <Task pending coro=<StreamReader.read() running at /usr/lib/python3.7/asyncio/streams.py:640> cb=[_release_waiter(<Future pendi...ab3a77710>()]>)() at /usr/lib/python3.7/asyncio/tasks.py:392]> got Future <Future pending> attached to a different loop

If I catch the exception, and proceed, everything is working fine.

One thing to note is, that my threads are started from an async function, but the callbacks themselves are synchronous. So the structure is something like: async-->sync threads-->async.run

Unfortunately, I cannot change the behavior of callbacks, as they are part of a 3rd party library (boto3) which is why I am resorting to async.run which works totally fine, but causes these Future warnings.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source