From a3490b125b96dfe9cd66aa9068ba7d60fbd0d812 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20=C3=96zt=C3=BCrk?= <97892689+burakozturk1@users.noreply.github.com> Date: Mon, 6 Jan 2025 21:56:20 +0300 Subject: [PATCH] Create threaded_burak_ozturk.py --- Week07/threaded_burak_ozturk.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Week07/threaded_burak_ozturk.py diff --git a/Week07/threaded_burak_ozturk.py b/Week07/threaded_burak_ozturk.py new file mode 100644 index 00000000..71910c10 --- /dev/null +++ b/Week07/threaded_burak_ozturk.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): + thread_list = [] + for n in range(self.num_threads): + t = threading.Thread(target=func, args=args, kwargs=kwargs, name=f"Thread-{n}") + thread_list.append(t) + t.start() + + for t in thread_list: + t.join() + + return run_threads + + return ThreadManager(num_threads)