Volker L
02/17/2023, 3:35 PMRuntimeError: There is no current event loop in thread 'AnyIO worker thread'.
Inside one of my tasks, I am using asynio and aiohttp to request some data from a RestAPI.Nate
02/17/2023, 3:36 PMVolker L
02/17/2023, 3:39 PMNate
02/17/2023, 3:41 PMVolker L
02/17/2023, 3:52 PMfrom parallel_requests import parallel_requests, parallel_requests_async
from prefect import task, flow
@task
def download(urls):
return parallel_requests(urls)
@task
async def download_async(urls):
return await parallel_requests_async(urls)
@flow
def run():
urls = ["<https://query2.finance.yahoo.com/v7/finance/quote?symbols=AAPL>"]*10
res = download_async(urls)
print(res[0])
if __name__=='__main__':
run()
The library parallel_requests
uses asyncio to run async functions. That seems to be not compatible with AnyIO
(which prefect is using??).
When I switch to parallel_requests_async
, the flow is running without any problems.
Note: parallel_requests
is my own lib, which you can find here: https://github.com/legout/parallel-requests