I am making a simple http server (yes I know Python already has the modules to do so) and when I get a request I create a new thread to handle it. Now, when I try to use ^C to exit in the shell, the program keeps going. What do I need to do to kill this program w/o having to resort to actually using 'kill'?
Well, I found that I can catch a KeyboardInterrupt in main() and use subprocess.call() to call kill on a linux system. Not an elegant solution I suppose.
I've been using python for a few months now, it's just the threads that I have little experience with. Hopefully someone else can chime in.
I came across the threading.Event() object and created a class variable like so:
self.setstop = threading.Event()
Then I have a class method with the following:
self.setstop.set()
I call this method from the main thread before the program exits (when I hit ^C) on all my threads. I have a threading.timer on each thread as well which periodically checks the condition self.setstop.isSet(), and will call thread.exit() if it is true, but this doesn't seem to exit right away. Maybe because I am using threading.Thread to thread a class?
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks