exit entire process in threaded script

H

Hank

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
 
P

Peter Hansen

Hank said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,132
Latest member
TeresaWcq1
Top