Hey everyone. I am writing a threaded server and want to check if the the handler thread is being told to exit. I have code like so:
So my main thread will call thread.stop() when it wants to exit. I just want statusCheck() to run every few seconds to check if the thread should exit and if the connection with the client is still good. Is this code ok?Code:def __init__(self,...,..): self.timer = threading.Event() def stop(self): self.event.set() def statusCheck(self): if self.event.isSet(): self.exit() self.timer = threading.Timer(10, self.statusCheck) self.timer.start() def recvMsgs(self): self.timer = threading.Timer(10, self.statusCheck) self.timer.start() do stuff....
On another note, how can you determine if a client has closed their end of the socket?
Ok I just realized that I can use select() for this particular application but I am still curious if there is another way. Basically I have a thread running and making a blocking call within a loop that I need to interrupt occasionally so it doesn't just sit there and block all day.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks