Skip to content

Commit c16e4f6

Browse files
authored
Merge pull request #852 from firatadar/patch-9
Create threaded_firat_adar_dal.py
2 parents 289bebd + 2ccc70d commit c16e4f6

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

Week07/threaded_firat_adar_dal.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import threading
2+
3+
def threaded(num_threads):
4+
class ThreadManager:
5+
def __init__(self, num_threads):
6+
self.num_threads = num_threads
7+
8+
def __call__(self, func):
9+
def run_threads(*args, **kwargs):
10+
threads = []
11+
for i in range(self.num_threads):
12+
thread = threading.Thread(target=func, args=args, kwargs=kwargs, name=f"Thread-{i}")
13+
threads.append(thread)
14+
thread.start()
15+
16+
for thread in threads:
17+
thread.join()
18+
19+
return run_threads
20+
21+
return ThreadManager(num_threads)

0 commit comments

Comments
 (0)