Closed Thread
Results 1 to 2 of 2

Thread: threading.Timer usage

  1. #1
    codeLoad is offline Newbie
    Join Date
    Feb 2009
    Posts
    16
    Rep Power
    0

    threading.Timer usage

    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:

    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....
    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?

    On another note, how can you determine if a client has closed their end of the socket?

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    codeLoad is offline Newbie
    Join Date
    Feb 2009
    Posts
    16
    Rep Power
    0

    Re: threading.Timer usage

    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.

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Noob to Threading, etc.
    By HobbyistCoder in forum C# Programming
    Replies: 0
    Last Post: 07-16-2011, 06:01 PM
  2. [C]Threading
    By AdvMutant in forum C and C++
    Replies: 2
    Last Post: 12-05-2010, 10:34 PM
  3. Threading in PHP
    By aerosko0315 in forum PHP Development
    Replies: 3
    Last Post: 07-29-2010, 10:46 AM
  4. Threading
    By Grouchotron in forum Java Help
    Replies: 1
    Last Post: 07-22-2010, 06:24 AM
  5. Threading problem?
    By danbt in forum C# Programming
    Replies: 1
    Last Post: 04-24-2010, 06:43 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts