+ Reply to Thread
Results 1 to 2 of 2

Thread: threading.Timer usage

  1. #1
    Newbie codeLoad is an unknown quantity at this point
    Join Date
    Feb 2009
    Posts
    14

    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. #2
    Newbie codeLoad is an unknown quantity at this point
    Join Date
    Feb 2009
    Posts
    14

    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.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

     

Similar Threads

  1. Replies: 0
    Last Post: 08-31-2009, 07:10 AM
  2. How to seperate a MDI form in different section of usage.
    By evk_87 in forum Visual Basic Programming
    Replies: 0
    Last Post: 03-27-2009, 07:35 AM
  3. what is the usage of &$ ?
    By yonghan in forum PHP Forum
    Replies: 3
    Last Post: 03-22-2009, 02:08 AM
  4. Memory usage by user
    By Tor in forum Linux/Unix General
    Replies: 3
    Last Post: 02-21-2008, 05:47 PM
  5. Acceptable CPU Usage
    By leon in forum PHP Forum
    Replies: 2
    Last Post: 06-10-2006, 08:32 PM

Bookmarks

Bookmarks

     
        Algorithms and Data Structures

        Java tutorials

        Algorithms Forum

Posting Permissions

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