From 7ccc25626414ed927389b1b65e26f3f86f2c8cb3 Mon Sep 17 00:00:00 2001 From: SuperSonic Date: Mon, 2 Sep 2019 20:54:54 +0800 Subject: [PATCH] Fix Timeout --- libs/connection.py | 4 +++- libs/yuuki.py | 24 +++++++++++++++--------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/libs/connection.py b/libs/connection.py index 9bb425e..10c79db 100644 --- a/libs/connection.py +++ b/libs/connection.py @@ -41,10 +41,12 @@ class Yuuki_Connect: self.helper_ids = [] self.helper_authTokens = {} - def connect(self): + def connect(self, listen_timeout=600000): transport = THttpClient.THttpClient(self.host + self.com_path) transport_in = THttpClient.THttpClient(self.host + self.poll_path) + transport_in.setTimeout(listen_timeout) + transport.setCustomHeaders(self.con_header) transport_in.setCustomHeaders(self.con_header) diff --git a/libs/yuuki.py b/libs/yuuki.py index e11d8bd..ed4d10d 100644 --- a/libs/yuuki.py +++ b/libs/yuuki.py @@ -1,7 +1,8 @@ #!/usr/bin/python3 # coding=UTF-8 -import os, time, \ +import socket, \ + os, time, \ json, ntpath, \ random, requests, \ platform, traceback @@ -18,7 +19,7 @@ class Yuuki_Settings: config = { "name": "Yuuki", - "version": "v6.5.1", + "version": "v6.5.1_RC1", "project_url": "https://tinyurl.com/syb-yuuki", "man_page": "https://tinyurl.com/yuuki-manual", "privacy_page": "OpenSource - Licensed under MPL 2.0", @@ -671,9 +672,9 @@ class Yuuki: def Main(self): NoWork = 0 - NoWorkLimit = 300 - fetchNum = 50 + NoWorkLimit = 5 + fetchNum = 50 catchedNews = [] ncMessage = Operation() @@ -688,17 +689,22 @@ class Yuuki: if time.localtime().tm_hour != self.data.getData("Global")["LastResetLimitTime"]: self.limitReset() self.data.updateData(self.data.getData("Global"), "LastResetLimitTime", time.localtime().tm_hour) - if NoWork >= NoWorkLimit: - self.revision = self.getClient(self.MyMID).getLastOpRevision() - catchedNews = self.listen.fetchOperations(self.revision, fetchNum) + if NoWork >= NoWorkLimit: + NoWork = 0 + self.revision = self.client.getLastOpRevision() + + try: + catchedNews = self.listen.fetchOperations(self.revision, fetchNum) + except socket.timeout: + print("Timeout") + NoWork += 1 + if catchedNews: NoWork = 0 self.Thread_Exec(self.taskDemux, (catchedNews,)) if len(catchedNews) > 1: self.revision = max(catchedNews[-1].revision, catchedNews[-2].revision) - else: - NoWork += 1 if self.data.Data != self.YuukiVariable["sync"]: self.data.Data = self.YuukiVariable["sync"]