这是我的源代码,每1秒执行一次函数
买,它只执行一次。你知道吗
简而言之,我想每秒钟从指定的管道输出中获取#
行
对这个问题有什么建议吗?你知道吗
谢谢你的帮助
class Monitor:
def __init__(self, namedpipe, name):
self.namedpipe = namedpipe
self.name = name
self.count = 0
def run(self):
print self.name+" start run"
while True:
line = self.namedpipe.readline()
self.count = self.count+1
def getCost(self):
print "Hi"
while True:
line = monitor.readline()
line = line.strip()
if not line:
ans =raw_input('stop?')
if ans=='y': break
monitorList = open(line, 'r')
m = Monitor(monitorList, line)
thread.start_new_thread(m.run, ())
time.sleep(1)
threading.Timer(0.1, m.getCost).start()
与线程计时器,您必须在计时器每次过期时重新启动它—因此在执行计时器过期时调用的函数期间—代码中的m.getCost—必须再次启动计时器。您可能需要定义一个包装函数来完成这项工作,以避免用计时器的东西污染m.getCost()。你知道吗
相关问题 更多 >
编程相关推荐