[Grok-dev] Execute function when server is shut down

Sylvain Viollon sylvain at infrae.com
Thu Jan 13 04:18:47 EST 2011


On Wed, 12 Jan 2011 12:30:39 -0500
Hector Blanco <white.lists at gmail.com> wrote:

  Hello,

> Yeah... I should've thought about that before sending the mail...
> Since the __init__ is only called when I create a new instance of my
> server, I should have realized that, in the best case the __del__
> method would be called when an instance of the server is removed in
> the server control page.
> 
> Surprisingly (well... surprisingly for a newbie that doesn't have much
> idea about how all that works) that doesn't happen... The __del__
> method is not called when I remove an application.
> 

  I don't thing we lower being should play with __del__ method: defining
  it disable the circular reference detection in the Python garbage
  collector, making easy to create memory leaks (if I remember
  correctly). So if you define it, you have to pay attention to what
  refer your object, because if you have a cycle, it might never be
  called.

  After if your wish is to call some code at shutdown time, and you pay
  attention to the reference, you have the problem that when your
  __del__ method will be called at shutdown time: half of the Python
  modules will be already unloaded (i.e. their memory freed), so except
  some basic Python code, you cannot do a lot.

> Well... maybe a workaround might be catching the signal send by the
> operative system... (just saying... I don't know if that makes much
> sense)
>
  You don't have such things on Windows.

  atexit is the safest solution, but the Zope database will be already
  closed, you will have to reopen it, if you need it.

  Regards,

  Sylvain,

-- 
Sylvain Viollon -- Infrae
t +31 10 243 7051 -- http://infrae.com
Hoevestraat 10 3033GC Rotterdam -- The Netherlands


More information about the Grok-dev mailing list