March 2019
Beginner
490 pages
12h 40m
English
In the following example, we will import the modules that we need and then create our first coroutine using the async syntax. This coroutine is called download_file, and it uses Python's requests module to download whatever file is passed to it. When it is done, it will return a message that's related to the file that is being downloaded.
You can find the following code in the download_files_asyncio.py file:
#!/usr/bin/python3import asyncioimport osimport requestsimport timefiles = ['https://docs.python.org/3/archives/python-3.7.2-docs-pdf-letter.zip', 'https://docs.python.org/3/archives/python-3.7.2-docs-pdf-a4.zip']async def download_file(url): response = requests.get(url) filename = os.path.basename(url) ...
Read now
Unlock full access