Pythonのお勉強 Part17at TECH
Pythonのお勉強 Part17 - 暇つぶし2ch336:デフォルトの名無しさん
07/03/03 23:04:58
>>328
スレッド使えばできるんじゃね?下のコードだとなんか時々終わる時に
エラー出るけど、スレッド詳しい人ならちゃんと書けるはず。

import thread
import time
import os

def change():
    open("a.txt", "w").write("a")

def watch():
    t1 = None
    while 1:
        t2 = os.path.getmtime("a.txt")
        if t1 is not None and t1 != t2:
            print "changed"
        t1 = t2
        time.sleep(1)

change()
thread.start_new_thread(watch, ())

for _ in xrange(5):
    change()
    time.sleep(2)



次ページ
最新レス表示
レスジャンプ
類似スレ一覧
スレッドの検索
話題のニュース
おまかせリスト
オプション
しおりを挟む
スレッドに書込
スレッドの一覧
暇つぶし2ch