Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions Week07/threaded_berkin_yildirim.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import threading

def threaded(n):
"""
Decorator to run a function n times in separate threads.
"""
def decorator(func):
def wrapper(*args, **kwargs):
threads = []
for i in range(n):
thread = threading.Thread(target=func, args=args, kwargs=kwargs)
threads.append(thread)
thread.start()
for thread in threads:
thread.join()
wrapper.__name__ = func.__name__
wrapper.__doc__ = func.__doc__
wrapper.__module__ = func.__module__
return wrapper
return decorator
Loading