開発環境
- OS X Yosemite - Apple (OS)
- Emacs (CUI)、BBEdit - Bare Bones Software, Inc. (GUI) (Text Editor)
- Python 3.4 (プログラミング言語)
Introducing Python: Modern Computing in Simple Packages(Bill Lubanovic (著)、 O'Reilly Media)のChapter 10(Systems)、Things to Do 10.6.を解いてみる。
Things to Do 10.6.
コード(Eacs, BBEdit)
#!/usr/bin/env python3
# -*-c doing: utf-8 -*_
import multiprocessing
import time
import random
import os
def f():
seconds = random.randint(1, 5)
time.sleep(seconds)
print(os.getpid(), seconds, time.ctime())
for p in [multiprocessing.Process(target=f) for n in range(20)]:
p.start()
入出力結果(Terminal, IPython)
$ ./sample6.py 4530 1 Sat Apr 4 11:09:14 2015 4535 1 Sat Apr 4 11:09:14 2015 4538 1 Sat Apr 4 11:09:14 2015 4539 1 Sat Apr 4 11:09:14 2015 4541 1 Sat Apr 4 11:09:14 2015 4542 1 Sat Apr 4 11:09:14 2015 4543 1 Sat Apr 4 11:09:14 2015 4531 2 Sat Apr 4 11:09:15 2015 4533 2 Sat Apr 4 11:09:15 2015 4546 2 Sat Apr 4 11:09:15 2015 4548 2 Sat Apr 4 11:09:15 2015 4532 3 Sat Apr 4 11:09:16 2015 4534 3 Sat Apr 4 11:09:16 2015 4540 3 Sat Apr 4 11:09:16 2015 4545 3 Sat Apr 4 11:09:16 2015 4529 4 Sat Apr 4 11:09:17 2015 4536 4 Sat Apr 4 11:09:17 2015 4544 4 Sat Apr 4 11:09:17 2015 4547 4 Sat Apr 4 11:09:17 2015 4537 5 Sat Apr 4 11:09:18 2015 $
0 コメント:
コメントを投稿