|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
sys.exit() not closing the program
i've written a nice, multithreaded server that will be used in an upcoming service. that said, we were having problems killing the processes; they were causing more trouble than they should. the solution was to make it so when the server receives the command "die", it shuts itself down, thus avoiding the trouble of killing it ourselves. However, quite simply, sys.exit() will not work.
My impression is that all its doing is exiting the thread that interprets commands, because after you send "die", the server doesn't close, it just stops accepting commands. Note" I know for a fact that sys.exit() is called. Also, I don't want to use os._exit() because of how sloppy it is (as explained in the documentation. if this worry is unfounded, please let me know.) Does anyone have a suggestion for how to solve this problem, or a thought as to why this is happening? Thanks, Beeyah |
|
#2
|
||||
|
||||
|
Without seeing your code its kinda hard to imagin what's going on. Maybe you could attach the program in question, or at least, post the problem area.
If what your saying is right, and it sounds possible then you need a way to get the thread to shut down the whole program.. triggering SystemExit from outside the thread might work? Personally, I find raising SystemExit cleaner than using sys.exit(); but both work in the same way. Take care, Mark. |
|
#3
|
|||
|
|||
|
Yeah, raising SystemExit does the same thing as sys.exit(). Anyway, here's the offending code:
PHP Code:
|
|
#4
|
|||
|
|||
|
Quote:
AFAIK raising SystemExit permits you to exit without importing the sys modules, hence "cleaner". |
|
#5
|
|||
|
|||
|
thats good to know. thanks.
|
|
#6
|
|||
|
|||
|
Yep, calling sys.exit() or raising SystemExit in any thread other than the main one will kill the thread, but not the program. This is the expected behaviour, but it is not very well documented.
From the docs for the thread module: Quote:
The correct way to end the program is to send a signal to the main thread that it is time to finish, and call sys.exit from there. You could do this with a global threading.Event object. Dave - The Developers' Coach |
|
#7
|
|||
|
|||
|
thanks alot :)
|
|
#8
|
|||
|
|||
|
Nevermind all that, I figured it out. Thanks for your help
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > sys.exit() not closing the program |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|