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 adafe86 commit 70dda9dCopy full SHA for 70dda9d
Week07/threaded_berkin_yildirim.py
@@ -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