From bdfae51e730c67f95c9f12d7015397a0da38c1b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ege=20En=C3=A7?= <111919042+egeenc0@users.noreply.github.com> Date: Sun, 15 Dec 2024 08:23:42 +0300 Subject: [PATCH] Create threaded_ege_enc.py --- Week07/threaded_ege_enc.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 Week07/threaded_ege_enc.py diff --git a/Week07/threaded_ege_enc.py b/Week07/threaded_ege_enc.py new file mode 100644 index 00000000..6acff7d0 --- /dev/null +++ b/Week07/threaded_ege_enc.py @@ -0,0 +1,29 @@ +import threading + + +def threader(n : int): + """ + This function is a decorator which takes an integer n as an argument + and returns a threaded function. + + :param n:Number of threads + :return:Threaded function + + """ + def decorator(func): + def wrapper(): + threads = [] + for _ in range(n): # 5 thread oluştur + t = threading.Thread(target=func) + t.start() + threads.append(t) + for t in threads: + t.join() + return wrapper + return decorator + +@threader(4) +def func(): + print("Hello World") + +func()