Matt Wong-Kemp

07/21/2020, 7:24 PM
What's the 'proper' way to do async inside a prefect task? I'm dual-testing in Jupyter, so I'd like to keep the async bit working nicely, and as far as I can tell Prefect isn't running an event loop. At the minute I've got something that looks like this:
async def do_thing_async_impl(a,b,c):
    await ...

def do_thing(a,b,c):
    return asyncio.run_until.complete(do_thing_async(a,b,c))
but I'm getting an error:
Future <Future pending cb=[BaseSelectorEventLoop._sock_connect_done(9)()]> attached to a different loop')
Before I got digging into event loop fun, is there an easier way to do an async task?

Jim Crist-Harif

07/21/2020, 7:28 PM
Hi Matt, prefect doesn't have any built-in asyncio integration, we leave that up to users. The above code looks a little odd to me, did you mean
instead of
? I'd expect this to work. The issue you're seeing above relates to mixing event loops - some code is creating futures/sockets/stuff in one event loop and trying to use them in another event loop.

Matt Wong-Kemp

07/21/2020, 7:29 PM
yep sorry that's a mistype, it is