Why sys.exit does not exit ?

Gerhard Häring gerhard.haering at opus-gmbh.net
Thu Mar 13 10:01:30 EST 2003


Giorge <me at nospam.pls> wrote:
> Hi all, here is a small code snippet that should
> tell something about what I'm trying to do:
> 
> import sys, os, thread, time
> from threading import *
> [...]
> The problem here is that the sys.exit call doesn't
> terminate the program, which exits after the sleep
> call.
> 
> Can you help ? thanks.

sys.exit only exits the main thread. In order for the program to finish, you
have to complete all other threads, too.

The ugly hack for the "don't care" scenario is to use os._exit. But you should
know about the consequences (no cleanup is done whatsoever). IMO os._exit
should only be used as an "emergency exit".

-- Gerhard




More information about the Python-list mailing list