exit entire process in threaded script

Discussion in 'Python' started by Hank, Nov 6, 2003.

  1. Hank

    Hank Guest

    Hi,

    I have the following:

    def readuser():
    ...check for user input then exit entire script

    thread.start_new_thread(readuser,())

    while(forever):
    ...do something


    How can I exit the whole script from readuser()? sys.exit() only exits
    that thread and not the entire process. I'm trying not to use any
    win32 modules.

    python 1.5
    win2k

    thanks
     
    Hank, Nov 6, 2003
    #1
    1. Advertising

  2. Hank

    Peter Hansen Guest

    Hank wrote:
    >
    > I have the following:
    >
    > def readuser():
    > ...check for user input then exit entire script
    >
    > thread.start_new_thread(readuser,())
    >
    > while(forever):
    > ...do something
    >
    > How can I exit the whole script from readuser()? sys.exit() only exits
    > that thread and not the entire process. I'm trying not to use any
    > win32 modules.


    Since I don't see any other replies yet I'll give it a go.

    The simplest thing to do is to make sure that the thread
    that is doing the sys.exit() is the main thread (i.e. the
    one which starts up in the first place, and which launches
    all the other threads). Then, make the other threads
    daemon threads with Thread.set_daemon() (sp?) and when the
    main thread exits via sys.exit(), the other threads are all
    terminated.

    -Peter
     
    Peter Hansen, Nov 6, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?U2FuZHk=?=

    Code to Exit Web App and Exit Internet Explorer

    =?Utf-8?B?U2FuZHk=?=, Aug 3, 2005, in forum: ASP .Net
    Replies:
    7
    Views:
    7,963
    =?Utf-8?B?U2FuZHk=?=
    Aug 5, 2005
  2. Joe Smith
    Replies:
    4
    Views:
    66,056
    sandeep1976
    Nov 8, 2006
  3. Replies:
    2
    Views:
    479
    Jeff Epler
    May 31, 2005
  4. kaleem
    Replies:
    8
    Views:
    865
    Tad McClellan
    Dec 14, 2006
  5. Victor Hooi
    Replies:
    1
    Views:
    149
    Nobody
    Feb 10, 2013
Loading...

Share This Page