Closed Thread
Results 1 to 4 of 4

Thread: program will not exit while thread is running

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

    program will not exit while thread is running

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

  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: program will not exit while thread is running

    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.

  4. #3
    Root23 is offline Programmer
    Join Date
    Jan 2010
    Posts
    144
    Rep Power
    8

    Re: program will not exit while thread is running

    I wish I could help you, but I'm just getting started with Python.

    I'm sure someone will respond soon though. I'm guessing a lot of people are on here during the work week, and not as much on weekends.

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

    Re: program will not exit while thread is running

    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?

Closed Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. problems in running the program
    By rissa in forum C and C++
    Replies: 7
    Last Post: 10-09-2010, 02:21 PM
  2. Scheduler/VB6 program running in Linux Fedora
    By pu8y in forum Visual Basic Programming
    Replies: 6
    Last Post: 11-26-2009, 11:51 AM
  3. General program not compiling/running
    By shopnobhumi in forum Assembly
    Replies: 3
    Last Post: 09-15-2009, 08:57 PM
  4. Running flashfiles on diffrent thread
    By Righteous in forum Visual Basic Programming
    Replies: 0
    Last Post: 04-01-2009, 11:35 AM
  5. Windows Error while running the program
    By jwxie518 in forum C and C++
    Replies: 3
    Last Post: 03-11-2009, 12:34 PM

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