What's the 'proper' way to do async inside a prefe...
# prefect-community
m
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:
Copy code
async def do_thing_async_impl(a,b,c):
    await ...
    ...

@task
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?
j
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
asyncio.run
instead of
asyncio.run_until.complete
? 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.
m
yep sorry that's a mistype, it is
run