Skip to content
You signed in with another tab or window. Reload to refresh your session.
You signed out in another tab or window. Reload to refresh your session.
You switched accounts on another tab or window. Reload to refresh your session.
Dismiss alert
File tree Expand file tree Collapse file tree 1 file changed +17
-8
lines changed Expand file tree Collapse file tree 1 file changed +17
-8
lines changed Original file line number Diff line number Diff line change 3
3
import time
4
4
5
5
6
- def count_up (num ):
6
+ def synchronize (func ):
7
+ def lock_resource (* args , ** kwargs ):
8
+ global lock
9
+ lock .acquire ()
7
10
8
- global database , lock
11
+ try :
12
+ func (* args , ** kwargs )
13
+ finally :
14
+ lock .release ()
15
+
16
+ return lock_resource
17
+
18
+
19
+ @synchronize
20
+ def count_up (num ):
9
21
10
- lock . acquire ()
22
+ global database
11
23
12
- try :
13
- time .sleep (random .randrange (3 ))
14
- database .append (num )
15
- finally :
16
- lock .release ()
24
+ time .sleep (random .randrange (3 ))
25
+ database .append (num )
17
26
18
27
19
28
def main ():
You can’t perform that action at this time.
0 commit comments