-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patha.py
More file actions
24 lines (20 loc) · 681 Bytes
/
a.py
File metadata and controls
24 lines (20 loc) · 681 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# Multiprocessing is when multiple processes are spawn from the main process, each having its own CPU and memory.
import time
import multiprocessing
def some_task():
for _ in range(100_000_000):
x = 1 + 1
print("Finished task")
if __name__ == "__main__":
start = time.time()
# Create two threads
p1 = multiprocessing.Process(target=some_task)
p2 = multiprocessing.Process(target=some_task)
# Start running both threads
p1.start()
p2.start()
# Wait until both threads are complete, and join the process into a single thread
p1.join()
p2.join()
end = time.time()
print(f"Finished process in {end - start} seconds")