Not sure about this (never tried), but Python Library Reference says:

"Note: the functions registered via this module are not called when
the program is killed by a signal, when a Python fatal internal error
is detected, or when os._exit() is called."

Since Ctrl+C sends a SIGINT to your server process, I don't think
atexit registered function will be executed.

HTH,
 Andrea

On Oct 9, 2:17 am, Phil Fazio <[EMAIL PROTECTED]> wrote:
> I appreciate your quick response.  However, I don't think I'm doing it
> right... I tried putting the following code in my
> app_globals.Globals.__init__() method:
>
>     import atexit
>     import fooapp.models.database as db
>     atexit.register(db.close_environment)
>
> where my close_environment() method is:
>
> def close_environment():
>     environment.close()
>     print "Database environment closed."
>
> but when i use Ctrl+C to quit my server process, nothing is printed to
> the console.  Does this mean I've placed the code in the wrong spot,
> or does it exit silently?
>
> Thanks!
>
> Phil
>
> On Oct 8, 7:51 pm, Philip Jenvey <[EMAIL PROTECTED]> wrote:
>
> > On Oct 8, 2008, at 3:40 PM, Phil Fazio wrote:
>
> > > I was wondering if there were a way to run methods or execute code on
> > > server shutdown (Ctrl+C, or otherwise).  I'd like to close a Berkeley
> > > DB environment I'm running so as to avoid a potential nasty bug -- I
> > > tried adding code to the __del__() method of app_globals.py, but it
> > > doesn't seem to execute.  Any help is greatly appreciated!
>
> > Sure, you want the atexit module.
>
> > --
> > Philip Jenvey

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to