From d54b2faa62d1370734d2a64fc5cf8324694a0d55 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:25:29 +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..1e0905fd --- /dev/null +++ b/Week07/threaded_ege_enc.py @@ -0,0 +1,29 @@ +import threading + + +def threaded(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 + +@threaded(4) +def func(): + print("Hello World") + +func()