From 972d5dfbd9e5a925ece6515579f543fd4fab4233 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Berkin=20Y=C4=B1ld=C4=B1r=C4=B1m?= <161759242+berkinyl@users.noreply.github.com> Date: Sat, 4 Jan 2025 20:09:56 +0300 Subject: [PATCH] Created threaded_berkin_yildirim.py --- Week07/threaded_berkin_yildirim.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Week07/threaded_berkin_yildirim.py diff --git a/Week07/threaded_berkin_yildirim.py b/Week07/threaded_berkin_yildirim.py new file mode 100644 index 00000000..42cfdfe7 --- /dev/null +++ b/Week07/threaded_berkin_yildirim.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