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()