-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy path029.Test_gevent_sleep.py
More file actions
39 lines (29 loc) · 859 Bytes
/
029.Test_gevent_sleep.py
File metadata and controls
39 lines (29 loc) · 859 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# -*-coding:utf-8-*-
# @auth ivan
# @time 20191029 ///
# @goal test for gevent sleep
from gevent import monkey
monkey.patch_all()
import gevent
import time
import random
def sleep(i, sleeptime):
sleeptimes = 0
sleeptimes = sleeptimes + sleeptime
time.sleep(sleeptime)
sleeptime1 = random.randint(sleeptime, 2)
sleeptimes = sleeptimes + sleeptime1
time.sleep(sleeptime)
sleeptime2 = random.uniform(sleeptime1, 2)
sleeptimes = sleeptimes + sleeptime2
time.sleep(sleeptimes)
print(i, sleeptimes)
time0 = time.time()
for j in range(1):
spawnlist = []
for i in range(9999):
sleeptime = random.randint(1, 2)
spawnlist.append(gevent.spawn(sleep, i, sleeptime))
gevent.joinall(spawnlist)
print('%d Task%d Time = %f' % (i + 1, j + 1, time.time() - time0))
# 9999 Task1 Time = 10.289901