【发布时间】:2014-07-30 20:21:47
【问题描述】:
我有一个 twitter 流(通过 Twython)正在运行。我想在指定时间(以秒为单位)后断开连接(),而不是简单地依赖键盘中断。 作为编程新手,我不清楚在哪里找到有问题的语句:Running a python script for a user-specified amount of time? 应该放在哪里(鉴于我正在使用流媒体类)。 目前,我的代码如下:
class MyStreamer(TwythonStreamer): #import from twython
def on_success(self, data):
json.dump(data,outfilePrep.outfile,sort_keys=False,indent=1)
def on_error(self, status_code, data):
print(status_code)
outfilePrep.outfile.close()
stream = MyStreamer(<credentials>)
stream.statuses.filter(track=<stuff>,locations=<otherstuff>)
感谢您的帮助,感谢您对新手的轻松。
【问题讨论】:
标签: python multithreading time stream control-flow