我尝试使用tryCatch
和Sys.sleep
来自动执行以下块,因此我不需要每15分钟继续返回并重新运行代码。< / p>
Twitter允许每15分钟下载一定数量的推文。在您达到最大值后,会出现错误消息。收到错误消息15分钟后,您可以下载的推文数量会重置。
列表(x)是我需要下载推文的几百个句柄。
# get initial list of Twitter Handles from df
x <- as.vector(df$Handle)
# get list of existing files from folder
f <- list.files("C:/workDump/")
# subset list of files if necessary
xSubset <- x[length(f):(length(x))]
# download the twitter timeline data for list elements which do not exist
for (i in xSubset){
timeline <- userTimeline(i,n = 3200)
timeline <- twListToDF(timeline)
save(timeline, file=paste("workDump/", i, ".Rda"))
}
我已经使用了tryCatch
和Sys.sleep
的各种规格,此时我只是在混淆自己。
答案 0 :(得分:0)
由于我无法使用您的代码,我只能猜测:
import socket
import sys
import time
import thread
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_address = ('localhost', 15000)
sock.bind(server_address)
sock.listen(1)
connection, client_address = sock.accept()
Servername = raw_input('Starting the chat(enter "QUIT" to discontinue), Please enter your name: ')
def Server_outgoing():
while True:
outgoing_message_server = raw_input()
if (outgoing_message_server == 'Quit' or outgoing_message_server == 'quit' or outgoing_message_server == 'QUIT'):
print "Server has decided to abort the chat - Bye bye"
break
print "######################################################################"
print >>sys.stderr, '"%s" : Printing outgoing message from Server "%s"' % (Servername, outgoing_message_server)
print "######################################################################"
connection.sendall(outgoing_message_server)
try:
thread.start_new_thread(Server_outgoing, ())
finally:
connection.close()
超时15 * 60秒。