Skip to content

Instantly share code, notes, and snippets.

@amaciel81
Created March 8, 2021 07:33
Show Gist options
  • Save amaciel81/c35fca540d47d5cb0e7a7b40c6b556f1 to your computer and use it in GitHub Desktop.
Save amaciel81/c35fca540d47d5cb0e7a7b40c6b556f1 to your computer and use it in GitHub Desktop.
from multiprocessing import Process
def multithread_scheduler(instances: int, worker: Callable, args: List[Any]) -> None:
threads = [
Thread(target=worker, args=args)
for _ in range(instances)
]
for thread in threads:
thread.start()
for thread in threads:
thread.join()
print("Multithread Execution, CPU bound")
with timer():
multithread_scheduler(8, cpu_worker, [10_000_000, 49])
print("Multithread Execution, I/O bound")
with timer():
multithread_scheduler(8, io_worker, [3])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment