8000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent d4759f7 commit 61de19bCopy full SHA for 61de19b
experiments/threads2.py
@@ -3,17 +3,26 @@
3
import time
4
5
6
-def count_up(num):
+def synchronize(func):
7
+ def lock_resource(*args, **kwargs):
8
+ global lock
9
+ lock.acquire()
10
- 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):
21
- lock.acquire()
22
+ global database
23
- try:
- time.sleep(random.randrange(3))
- database.append(num)
- finally:
- lock.release()
24
+ time.sleep(random.randrange(3))
25
+ database.append(num)
26
27
28
def main():
0 commit comments