Skip to content

Create threaded_ege_enc.py #799

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions Week07/threaded_ege_enc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
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(*args, **kwargs):
threads = []
for _ in range(n):
t = threading.Thread(target=func, args=args, kwargs=kwargs)
t.start()
threads.append(t)
for t in threads:
t.join()
return wrapper
return decorator

@threaded(4)
def func(value):
print(f"Hello World: {value}")

# Test
func("dummy")
Loading