Lower checking frequency on inactivity
This commit is contained in:
parent
4c12ffc375
commit
2f24db2f14
@ -80,6 +80,10 @@ def addEventHandler(event,func):
|
|||||||
def sendResponse(connection,data):
|
def sendResponse(connection,data):
|
||||||
connection.sendall(len(data).to_bytes(4,"big") + data)
|
connection.sendall(len(data).to_bytes(4,"big") + data)
|
||||||
|
|
||||||
|
senderThreadSleepMin = 0.0333
|
||||||
|
senderThreadSleepMax = 1.0
|
||||||
|
senderThreadSleepIncr = 0.05
|
||||||
|
|
||||||
class senderThread(threading.Thread):
|
class senderThread(threading.Thread):
|
||||||
def __init__(self,connectionThread):
|
def __init__(self,connectionThread):
|
||||||
threading.Thread.__init__(self)
|
threading.Thread.__init__(self)
|
||||||
@ -87,24 +91,41 @@ class senderThread(threading.Thread):
|
|||||||
with self.lock:
|
with self.lock:
|
||||||
self.connectionThread = connectionThread
|
self.connectionThread = connectionThread
|
||||||
self.queue = []
|
self.queue = []
|
||||||
|
self.newQueue = False
|
||||||
|
self.sleep = senderThreadSleepMin
|
||||||
|
|
||||||
def closeThread(self):
|
def closeThread(self):
|
||||||
with self.lock:
|
with self.lock:
|
||||||
self.queue = [["close"]]
|
self.queue = [["close"]]
|
||||||
|
self.newQueue = True
|
||||||
|
|
||||||
def addToQueue(self,entry):
|
def addToQueue(self,entry):
|
||||||
with self.lock:
|
with self.lock:
|
||||||
self.queue.append(entry)
|
self.queue.append(entry)
|
||||||
|
self.newQueue = True
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
sleepTime = 0
|
||||||
while True:
|
while True:
|
||||||
time.sleep(0.0333)
|
|
||||||
with self.lock:
|
with self.lock:
|
||||||
if len(self.queue) == 0: continue
|
sleepTime = self.sleep
|
||||||
|
|
||||||
|
print(sleepTime)
|
||||||
|
time.sleep(sleepTime)
|
||||||
|
|
||||||
|
with self.lock:
|
||||||
|
if not self.newQueue:
|
||||||
|
if self.sleep < senderThreadSleepMax:
|
||||||
|
self.sleep += senderThreadSleepIncr * self.sleep
|
||||||
|
if self.sleep > senderThreadSleepMax: self.sleep = senderThreadSleepMax
|
||||||
|
continue
|
||||||
|
|
||||||
for entry in self.queue:
|
for entry in self.queue:
|
||||||
if entry[0] == "close": return
|
if entry[0] == "close": return
|
||||||
entry[0](*entry[1],**entry[2])
|
entry[0](*entry[1],**entry[2])
|
||||||
self.queue = []
|
self.queue = []
|
||||||
|
self.newQueue = False
|
||||||
|
self.sleep = senderThreadSleepMin
|
||||||
|
|
||||||
class connectionThread(threading.Thread):
|
class connectionThread(threading.Thread):
|
||||||
def __init__(self,threadId,connection,address):
|
def __init__(self,threadId,connection,address):
|
||||||
|
Loading…
Reference in New Issue
Block a user