Created
October 2, 2014 08:26
-
-
Save aoshiman/b52f79d0f75b09ecf9c6 to your computer and use it in GitHub Desktop.
threading モジュールを使ったサンプルスクリプト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
from time import time | |
from threading import Thread | |
""" | |
http://gihyo.jp/dev/serial/01/pythonhacks/0005 | |
Python3 threading モジュールを使ったサンプル | |
""" | |
def f(): | |
'''カウントアップ | |
''' | |
i = 0 | |
while i < 10000000: | |
i = i + 1 | |
def ThreadTest(): | |
lst = [] | |
# スレッドの生成 | |
for i in range(2): | |
lst.append( Thread(target=f) ) | |
start = time() | |
# スレッドの開始 | |
for t in lst: | |
t.start() | |
# スレッドが終了するまで待つ | |
for t in lst: | |
t.join() | |
finish = time() | |
print('threding:', finish - start) | |
if __name__ == '__main__': | |
ThreadTest() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment