Skip to content

Commit 70dda9d

Browse files
authored
Create threaded_berkin_yildirim.py
1 parent adafe86 commit 70dda9d

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

Week07/threaded_berkin_yildirim.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import threading
2+
3+
def repeat_in_threads(times):
4+
"""
5+
Decorator to execute a function multiple times in separate threads.
6+
"""
7+
def apply_decorator(target_function):
8+
def execute_in_threads(*args, **kwargs):
9+
thread_list = []
10+
for _ in range(times):
11+
t = threading.Thread(target=target_function, args=args, kwargs=kwargs)
12+
thread_list.append(t)
13+
t.start()
14+
for t in thread_list:
15+
t.join()
16+
execute_in_threads.__name__ = target_function.__name__
17+
execute_in_threads.__doc__ = target_function.__doc__
18+
execute_in_threads.__module__ = target_function.__module__
19+
return execute_in_threads
20+
return apply_decorator

0 commit comments

Comments
 (0)