From 6d4ea30f5e55931dca29aadc8b77400fb359429a Mon Sep 17 00:00:00 2001 From: sas5188 <148003648+sas5188@users.noreply.github.com> Date: Mon, 18 May 2026 07:50:30 +0300 Subject: [PATCH] Create threaded_murad_maharramli.py --- Week07/threaded_murad_maharramli.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 Week07/threaded_murad_maharramli.py diff --git a/Week07/threaded_murad_maharramli.py b/Week07/threaded_murad_maharramli.py new file mode 100644 index 00000000..b6f0441e --- /dev/null +++ b/Week07/threaded_murad_maharramli.py @@ -0,0 +1,28 @@ +import threading +from functools import wraps + +def threaded(n: int): + """ + A decorator that executes the wrapped function in 'n' separate threads. + It handles creating, starting, and synchronizing (joining) the threads. + """ + def decorator(func): + @wraps(func) + def wrapper(*args, **kwargs): + threads = [] + + # Create n threads, pointing them to the target function + for _ in range(n): + t = threading.Thread(target=func, args=args, kwargs=kwargs) + threads.append(t) + + # Start all threads + for t in threads: + t.start() + + # Synchronize the threads by waiting for all of them to finish + for t in threads: + t.join() + + return wrapper + return decorator