From 91c6fcfac6affc2ae9fe264be4a76e2574e48bf3 Mon Sep 17 00:00:00 2001 From: Eren Yurtcu <137696300+erenyurtcu@users.noreply.github.com> Date: Tue, 3 Dec 2024 14:18:42 +0300 Subject: [PATCH] Create threaded_ismeteren_yurtcu.py --- Week07/threaded_ismeteren_yurtcu.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Week07/threaded_ismeteren_yurtcu.py diff --git a/Week07/threaded_ismeteren_yurtcu.py b/Week07/threaded_ismeteren_yurtcu.py new file mode 100644 index 00000000..42cfdfe7 --- /dev/null +++ b/Week07/threaded_ismeteren_yurtcu.py @@ -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