Skip to content

Commit 9f8fe0e

Browse files
authored
Merge pull request #814 from berkinyl/patch-10
Create threaded_berkin_yildirim.py
2 parents fea20f7 + 972d5df commit 9f8fe0e

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 threaded(n):
4+
"""
5+
Decorator to run a function n times in separate threads.
6+
"""
7+
def decorator(func):
8+
def wrapper(*args, **kwargs):
9+
threads = []
10+
for i in range(n):
11+
thread = threading.Thread(target=func, args=args, kwargs=kwargs)
12+
threads.append(thread)
13+
thread.start()
14+
for thread in threads:
15+
thread.join()
16+
wrapper.__name__ = func.__name__
17+
wrapper.__doc__ = func.__doc__
18+
wrapper.__module__ = func.__module__
19+
return wrapper
20+
return decorator

0 commit comments

Comments
 (0)