multiprocessのテスト
| 登録日 | :2025/03/30 07:25 |
|---|---|
| カテゴリ | :Python基礎 |
テストコード
#Chapter 4 child_process.py
import os
from multiprocessing import Process
def run_child() -> None:
print("Child: I am the child process.")
print(f"Child: Child's PID: {os.getpid()}")
print(f"Child: Parent's PID: {os.getppid()}")
def start_parent(num_children: int) -> None:
print("Parent : I am the parent process")
print(f"Parent: Parent's PID: {os.getpid()}")
for i in range(num_children):
print(f"Starting Proces {i}")
Process(target=run_child).start()
if __name__ == '__main__':
num = 3
start_parent(num)