#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2004
    Location
    INDIA
    Posts
    31
    Rep Power
    11

    To get thread id and ask it to stop cleanly


    Well I am using threading.Thread.

    In my application there will be at some time multiple threads will be running. Now if user tries to close the application than at that moment I just want to implement following:

    1.0 Check are there some active worker threads
    2.0 If yes then prompt to user Messagebox that already threads are running do you still want to close application
    3.0 If user tells yes then just get all active thread one by one and try to stop them cleanly

    4.0 I have to take care that socket which is created in my code is also closed

    Code:
    # Run function of thread
    def run():
     self.socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
     self.socket.connect((self.server,self.port))
     # Do something here
     self.socket.close()

    How to do this? Any ideas and suggestions...

    Sandeep
  2. #2
  3. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Meriden, Connecticut
    Posts
    1,797
    Rep Power
    154
    Look into the register() function of the atexit module. The threading module not only has the Timer() function will you will be able to use (and can cancel at any given time), but it has a function for retrieving any threads (processes) still currently running. So you will have to also look into that function to learn more. As for the message box, I would go with Tkinter for getting that done correctly.

IMN logo majestic logo threadwatch logo seochat tools logo