How to make a program exit? 
Author Message
 How to make a program exit?

What's the preferred way of making a multi-threaded program exit?

I have a SocketServer application using ThreadingMixin, i.e. a
multi-threaded socket listener.

I want the server to support a shutdown command, i.e. if a client
connects and sends a certain string, the whole server should shut
down gracefully.

In a non-threaded application I'd just call sys.exit(), but that
only collects the current listener thread rather than shutting down
the whole server.

I can think of some brutal ways to stop the server, but it's not clear
from the docs if there's a nice way.

Any advice?  Thanks.



Sun, 20 Jun 2004 20:54:40 GMT  
 How to make a program exit?


Quote:
>I can think of some brutal ways to stop the server, but it's not clear
>from the docs if there's a nice way.

>Any advice?  Thanks.

The recommended technique is to communicate somehow
with the running threads that they should commit suicide
and only kill them off if they haven't died in some acceptable
interval.  You should of course use a thread-safe method
of communication so that you don't get a memory access
exceptions.  Then your main thread waits until either they
have all complied with the request or the main thread
decides it must resort to {*filter*}.

So I guess this implies that you don't do operations that
block indefinitely.  There should be a time-out or some
signalling mechanism so that periodically your worker
threads can check the flag to see if it should shut
down.

Mike

--

"I don't want to belong to any club that would have me as a member."
    -- Groucho Marx



Mon, 21 Jun 2004 00:23:32 GMT  
 How to make a program exit?


Quote:

> In a non-threaded application I'd just call sys.exit(), but that
> only collects the current listener thread rather than shutting down
> the whole server.

> I can think of some brutal ways to stop the server, but it's not clear
> from the docs if there's a nice way.

They will always advice you to 'always wait for other threads
to finish' but we don't always care if other threads are finished
or not. I use os.exit() which does exit on multithread scripts.


Mon, 21 Jun 2004 16:32:18 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. want to tie the exit by windows, to the exit button in program

2. Quit LabVIEW (Exit) stops program but doesn't exit

3. code to exit on Exit ?

4. sys.exit() doesn't exit

5. how to exit from exit-onexit

6. exiting eval'ed script without exiting app

7. Why sys.exit does not exit ?

8. Exit tk application on Close Window (Exit on infinite loop)

9. expect doesn't exit exiting processes, help me

10. cdd 3 lockup on program exit

11. CPD 2.1 Exiting Program

12. Windows XP and Clarion RTF control (type anything and program exits)

 

 
Powered by phpBB® Forum Software