-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexamples.py
More file actions
44 lines (32 loc) · 741 Bytes
/
examples.py
File metadata and controls
44 lines (32 loc) · 741 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
40
41
42
43
44
from gevent import sleep, spawn, spawn_later
from shield import shield
@shield()
def work():
for _ in range(3):
print('programing...')
sleep(1)
@shield()
def exercise():
for _ in range(3):
print('push-up')
sleep(1)
def date():
sleep(3)
print("Wait... I don't have a girlfriend...")
def daily_life():
work()
exercise()
date()
g1 = spawn(daily_life)
g2 = spawn_later(2, g1.kill)
g1.join()
g2.join()
# print out will be:
##############################################
# programing...
# programing...
# programing... (kill happens, but postponed)
# push-up
# push-up
# push-up (date won't happen, because it's not shielded)
##############################################