Fix accumulating threads

This commit is contained in:
Fierelier 2021-04-14 05:12:35 +02:00
parent 19717d1094
commit e2c7a7f9a1

View File

@ -101,8 +101,9 @@ class inThread(threading.Thread):
self.connection = connection self.connection = connection
self.address = address self.address = address
def closeThread(self): def closeThread(self,closeConnection = True):
with threadsLock: with threadsLock:
if closeConnection:
for thread in outThreads: for thread in outThreads:
thread = outThreads[thread] thread = outThreads[thread]
if thread.user == self.user: if thread.user == self.user:
@ -122,7 +123,11 @@ class inThread(threading.Thread):
def run(self): def run(self):
try: try:
global threadId global threadId
data = self.connection.recv(1000).decode("utf-8") data = self.connection.recv(1000)
if data == b"":
self.closeThread()
return
data = data.decode("utf-8")
while data[-1] == " ": data = data[:-1] while data[-1] == " ": data = data[:-1]
args = commandToList(data) args = commandToList(data)
cmd = args.pop(0) cmd = args.pop(0)
@ -149,8 +154,10 @@ class inThread(threading.Thread):
with threadsLock: with threadsLock:
thread = outThread(self.threadId,self.connection,self.address,self.user) thread = outThread(self.threadId,self.connection,self.address,self.user)
outThreads[str(threadId)] = thread outThreads[str(self.threadId)] = thread
thread.start() thread.start()
self.closeThread(False)
return return
if cmd == "broadcast": if cmd == "broadcast":
@ -160,6 +167,9 @@ class inThread(threading.Thread):
while True: while True:
data = self.connection.recv(bufferSize) data = self.connection.recv(bufferSize)
if data == b"":
self.closeThread()
return
with threadsLock: with threadsLock:
for thread in outThreads: for thread in outThreads:
thread = outThreads[thread] thread = outThreads[thread]