From 2ccc70dc7fcc63a0640e85cf138b90175445a329 Mon Sep 17 00:00:00 2001 From: firatadar <108763085+firatadar@users.noreply.github.com> Date: Mon, 6 Jan 2025 22:16:14 +0300 Subject: [PATCH] Create threaded_firat_adar_dal.py --- Week07/threaded_firat_adar_dal.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Week07/threaded_firat_adar_dal.py diff --git a/Week07/threaded_firat_adar_dal.py b/Week07/threaded_firat_adar_dal.py new file mode 100644 index 00000000..4a4ccd04 --- /dev/null +++ b/Week07/threaded_firat_adar_dal.py @@ -0,0 +1,21 @@ +import threading + +def threaded(num_threads): + class ThreadManager: + def __init__(self, num_threads): + self.num_threads = num_threads + + def __call__(self, func): + def run_threads(*args, **kwargs): + threads = [] + for i in range(self.num_threads): + thread = threading.Thread(target=func, args=args, kwargs=kwargs, name=f"Thread-{i}") + threads.append(thread) + thread.start() + + for thread in threads: + thread.join() + + return run_threads + + return ThreadManager(num_threads)