Telegram Group & Telegram Channel
Your best companion in learning asyncio is asyncio.sleep. It works like time.sleep making the calling code wait the given number of seconds. This is the simplest example of an IO-bound task because while sleeping, your code literally does nothing but wait. And unlike time.sleep, asyncio.sleep is async. That means, while the calling task waits for it to finish, another task can be executed.

import asyncio
import time

async def main():
start = time.time()
await asyncio.sleep(2)
return int(time.time() - start)

asyncio.run(main())
# 2


You can't yet see how the code switches to another task while waiting because we have only one task. But bear with me, in the next posts we'll get to it.



tg-me.com/pythonetc/722
Create:
Last Update:

Your best companion in learning asyncio is asyncio.sleep. It works like time.sleep making the calling code wait the given number of seconds. This is the simplest example of an IO-bound task because while sleeping, your code literally does nothing but wait. And unlike time.sleep, asyncio.sleep is async. That means, while the calling task waits for it to finish, another task can be executed.

import asyncio
import time

async def main():
start = time.time()
await asyncio.sleep(2)
return int(time.time() - start)

asyncio.run(main())
# 2


You can't yet see how the code switches to another task while waiting because we have only one task. But bear with me, in the next posts we'll get to it.

BY Python etc


Warning: Undefined variable $i in /var/www/tg-me/post.php on line 280

Share with your friend now:
tg-me.com/pythonetc/722

View MORE
Open in Telegram


Pythonetc Telegram | DID YOU KNOW?

Date: |

The STAR Market, as is implied by the name, is heavily geared toward smaller innovative tech companies, in particular those engaged in strategically important fields, such as biopharmaceuticals, 5G technology, semiconductors, and new energy. The STAR Market currently has 340 listed securities. The STAR Market is seen as important for China’s high-tech and emerging industries, providing a space for smaller companies to raise capital in China. This is especially significant for technology companies that may be viewed with suspicion on overseas stock exchanges.

A project of our size needs at least a few hundred million dollars per year to keep going,” Mr. Durov wrote in his public channel on Telegram late last year. “While doing that, we will remain independent and stay true to our values, redefining how a tech company should operate.

Pythonetc from sg


Telegram Python etc
FROM USA