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 a165860 commit 21fec5dCopy full SHA for 21fec5d
Week07/threaded_bc.py
@@ -0,0 +1,42 @@
1
+import threading
2
+
3
4
+def threaded(n):
5
+ def decorator(func):
6
+ def _decorator(*args, **kwargs):
7
+ threads = []
8
+ for i in range(n):
9
+ t = threading.Thread(target=func, args=args, kwargs=kwargs)
10
+ threads.append(t)
11
+ # print(f"Threaded started thread {i+1} of {n} for {func.__name__}")
12
+ t.start()
13
+ for t in threads:
14
+ t.join()
15
16
+ return _decorator
17
18
+ return decorator
19
20
21
+if __name__ == "__main__":
22
23
+ @threaded(3)
24
+ def a():
25
+ print("a")
26
27
+ @threaded(2)
28
+ def b():
29
+ print("b")
30
31
+ @threaded(4)
32
+ def c():
33
+ print("c")
34
35
+ @threaded(1)
36
+ def d():
37
+ print("d")
38
39
+ a()
40
+ b()
41
+ c()
42
+ d()
0 commit comments