Lol, sorry if I seem to be "overly-asking" with my mini-wall of threads ive been making, but ive beein doing quite a bit of programming recently :p
Anywho, I'm writing a library that will connect to sockets and manage them, process its data, and do stuff based on that.
My problem lays on sending b"\r\n\x00" to the socket every 20 seconds. I thought that if I started a new thread for the ping function, that would work.
..however, time.sleep() seems to pause the whole entire program instead of what I thought would be just that thread
here's my code thus far:
def main(self):
recvbuf = b""
self.connect(self.group, self.user, self.password)
while self.connected:
rSocket, wSocket, error = select.select([x[self.group] for x in self.conArray], [x[self.group] for x in self.conArray], [x[self.group] for x in self.conArray], 0.2) #getting already made socket connections
for rChSocket in rSocket:
while not recvbuf.endswith(b"\x00"): #[-1] doesnt work on empty things... and recvbuf is empty.
recvbuf += rChSocket.recv(1024) #need the WHOLE message ;D
if len(recvbuf) > 0:
dataManager.manage(self, self.group, recvbuf)
recvbuf = b""
for wChSocket in wSocket:
t = threading.Thread(self.pingTimer(wChSocket)) #here's what I need to be ran every 20 seconds.
t.start()
chSocket.close()
and here's the pingTimer function:
def pingTimer(self, wChSocket):
time.sleep(20)
print(time.strftime("%I:%M:%S %p]")+"Ping test!") #I don't want to mini-DDoS
#wChSocket.send(b"\r\n\x00")
Thanks