開発環境
- macOS Mojave - Apple (OS)
- Emacs (Text Editor)
- Windows 10 Pro (OS)
- Visual Studio Code (Text Editor)
- Python 3.7 (プログラミング言語)
入門 Python 3 (Bill Lubanovic (著)、斎藤 康毅 (監修)、長尾 高弘 (翻訳)、オライリージャパン)の10章(システム)、10.5(復習問題)10-6.を取り組んでみる。
コード(Emacs)
Python 3
#!/usr/bin/env python3
import os
import multiprocessing
import random
import time
def func(seconds):
time.sleep(seconds)
print(f'PID {os.getpid()} {seconds}')
# n = 3
n = 10
for _ in range(n):
p = multiprocessing.Process(target=func, args=(random.randrange(1, 6),))
p.start()
入出力結果(Terminal, cmd(コマンドプロンプト), Jupyter(IPython))
$ ./sample6.py PID 8923 1 PID 8926 1 PID 8929 1 PID 8931 1 PID 8932 1 PID 8925 2 PID 8924 3 PID 8928 3 PID 8927 5 PID 8930 5 $
0 コメント:
コメントを投稿