Skip to content
Open
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
32 changes: 32 additions & 0 deletions Week07/threaded_furkan_baytak.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import threading

def threaded(n):
"""
Decorator to create n threads for a function.

Args:
n (int): Number of threads to create.

Returns:
function: A decorated function that runs in n threads.
"""
def decorator(func):
def wrapper(*args, **kwargs):
threads = []

# Function to be run in threads
def target_func():
func(*args, **kwargs)

# Create and start threads
for _ in range(n):
thread = threading.Thread(target=target_func)
threads.append(thread)
thread.start()

# Wait for all threads to complete
for thread in threads:
thread.join()

return wrapper
return decorator
Loading