Skip to content

Commit 21fec5d

Browse files
committed
Tests 4 W07
1 parent a165860 commit 21fec5d

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

Week07/threaded_bc.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)