Skip to content

Commit b3e86f4

Browse files
committed
Multiprocessing\S04-Daemon\S04-01-daemon-process
1 parent fef3bc5 commit b3e86f4

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from multiprocessing.context import Process
2+
import time
3+
import sys
4+
5+
6+
start = time.perf_counter()
7+
8+
def some_task(name):
9+
print(f"Process {name} Started.")
10+
time.sleep(3)
11+
print(f"Process {name} Finished.")
12+
13+
14+
if __name__ == "__main__":
15+
p1 = Process(target=some_task, args=("One", ), daemon=True)
16+
p2 = Process(target=some_task, args=("Two", ), daemon=True)
17+
p1.start()
18+
p2.start()
19+
20+
# p1.join()
21+
# p2.join()
22+
23+
end = time.perf_counter()
24+
exe_time = end - start
25+
print(f"Execution Time: {exe_time} sec")
26+
27+
sys.exit()

0 commit comments

Comments
 (0)