FAQ#
Does cached_path
have an async interface?#
No, not at the moment. But you can still benefit by calling cached_path()
concurrently
using asyncio.to_thread()
. For example:
>>> async def main():
... print("Downloading files...")
... await asyncio.gather(
... asyncio.to_thread(cached_path, "https://github.com/allenai/cached_path/blob/main/README.md"),
... asyncio.to_thread(cached_path, "https://github.com/allenai/cached_path/blob/main/setup.py"),
... asyncio.to_thread(cached_path, "https://github.com/allenai/cached_path/blob/main/requirements.txt"),
... )
... print("Finished all downloads")
...
>>> asyncio.run(main())
Downloading files...
Finished all downloads
>>>