Circuits - Python Event-Driven Framework
2009-08-12 - ⧖ 1.0 mincircuits というPythonのイベントドリブンなフレームワークがあります。 今日はさわりだけ。
ノーマルなtail -f 実装
import sys
from time import sleep
fp = open (sys .argv [1 ])
while True :
fp .seek (fp .tell ())
for line in fp .readlines ():
sys .stdout .write (line )
sleep (0.1 )
circuitsを使った tail -f 実装(公式サイトの例のまんまです)
import sys
from time import sleep
from circuits import Component
class Tail (Component ):
def __init__ (self , filename ):
super (Tail , self ).__init__ ()
self .filename = filename
self .fp = open (self .filename , "r" )
def __tick__ (self ):
self .fp .seek (self .fp .tell ())
for line in self .fp .readlines ():
sys .stdout .write (line )
sleep (0.1 )
tail = Tail (sys .argv [1 ])
tail .run ()
Twisted に挫折したクチなので、理解しきれるかな。 チュートリアルとかもうちょい勉強しよう。