I gave this a shot but haven't had much luck with it. When I try
os.execlp I get an error saying unknown file or directory. Whether this
is in reference to Python or my script I don't know, however python is
in my system's path variable and I'm running the script from the dir it
is located in.

At someone else's suggestion I tried using a loader script with
os.spawnv using the os.P_WAIT flag. Unfortunatly this exits right away
(presumably never starting my server). 

I also tried subprocess.Popen and then calling child.wait(). This sent
me into a loop of exceptions saying that the socket the server is
opening is already in use (even on the first try).

Does anyone know of a nice reliable app that already does this for you?
Open source preferably.

Ron Griswold
Character TD
R!OT Pictures
[EMAIL PROTECTED]

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf
Of Peter Hansen
Sent: Monday, January 16, 2006 5:40 PM
To: python-list@python.org
Subject: Re: Restarting scripts

Brian Cole wrote:
> If everything dies by a Python exception...
> 
> if __name__ == '__main__':
>     try:
>         main(sys.argv)
>     except:
>         os.execlp("python", "python", sys.argv)
> 
> Pretty nasty peice of code, but it works well for restarting your
script.

Noting that sys.exit() and possibly several other things can "raise 
SystemExit" and while it is a subclass of Exception (and gets caught by 
the above), it is usually considered a clean and intentional exit and 
changing the above to do this is probably best:

try:
    main(sys.argv)
except SystemExit:
    raise
except:
    os.execlp(.... etc etc

-Peter

-- 
http://mail.python.org/mailman/listinfo/python-list

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to