You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
832 B
46 lines
832 B
5 years ago
|
try:
|
||
1 year ago
|
import asyncio
|
||
5 years ago
|
except ImportError:
|
||
1 year ago
|
print("SKIP")
|
||
|
raise SystemExit
|
||
5 years ago
|
|
||
2 years ago
|
import time
|
||
5 years ago
|
|
||
2 years ago
|
if hasattr(time, "ticks_ms"):
|
||
|
ticks = time.ticks_ms
|
||
|
ticks_diff = time.ticks_diff
|
||
|
else:
|
||
5 years ago
|
ticks = lambda: int(time.time() * 1000)
|
||
|
ticks_diff = lambda t1, t0: t1 - t0
|
||
|
|
||
|
|
||
|
async def delay_print(t, s):
|
||
|
await asyncio.sleep(t)
|
||
|
print(s)
|
||
|
|
||
|
|
||
|
async def main():
|
||
|
print("start")
|
||
|
|
||
|
await asyncio.sleep(0.001)
|
||
|
print("after sleep")
|
||
|
|
||
|
t0 = ticks()
|
||
3 years ago
|
await delay_print(0.2, "short")
|
||
5 years ago
|
t1 = ticks()
|
||
3 years ago
|
await delay_print(0.4, "long")
|
||
5 years ago
|
t2 = ticks()
|
||
4 years ago
|
await delay_print(-1, "negative")
|
||
|
t3 = ticks()
|
||
|
|
||
|
print(
|
||
|
"took {} {} {}".format(
|
||
3 years ago
|
round(ticks_diff(t1, t0), -2),
|
||
|
round(ticks_diff(t2, t1), -2),
|
||
|
round(ticks_diff(t3, t2), -2),
|
||
4 years ago
|
)
|
||
|
)
|
||
5 years ago
|
|
||
|
|
||
|
asyncio.run(main())
|