Is there an method that I can use as a hook when an object is destroyed? (Im trying to save some _v_ data prior to destruction. Ive tried __del__ but this doesnt seem to get called. Thanks. -- Andy McKay, Developer. ActiveState.
If it's an object in an objectmanager, you can define a manage_beforeDelete() method on it (see ObjectManager.py). How are you destroying it? andym@ActiveState.com wrote:
Is there an method that I can use as a hook when an object is destroyed? (Im trying to save some _v_ data prior to destruction. Ive tried __del__ but this doesnt seem to get called.
Thanks.
-- Andy McKay, Developer. ActiveState.
_______________________________________________ Zope-Dev maillist - Zope-Dev@zope.org http://lists.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope )
-- Chris McDonough Digital Creations, Publishers of Zope http://www.zope.org
I was hoping to have this method fired Zope is shut down, restarted etc and not call it implicitly. The theory being if this object is cached it will have to be unloaded at some point? Ive used manage_beforeDelete() elsewhere and it works fine when Im destroying an object whilst ZODB is still running. Thanks. ----- Original Message ----- From: "Chris McDonough" <chrism@digicool.com> To: <andym@activestate.com> Cc: <zope-dev@zope.org> Sent: Monday, September 18, 2000 2:32 PM Subject: Re: [Zope-dev] __del__
If it's an object in an objectmanager, you can define a manage_beforeDelete() method on it (see ObjectManager.py).
How are you destroying it?
andym@ActiveState.com wrote:
Is there an method that I can use as a hook when an object is destroyed?
(Im
trying to save some _v_ data prior to destruction. Ive tried __del__ but this doesnt seem to get called.
Thanks.
-- Andy McKay, Developer. ActiveState.
_______________________________________________ Zope-Dev maillist - Zope-Dev@zope.org http://lists.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope )
-- Chris McDonough Digital Creations, Publishers of Zope http://www.zope.org
_______________________________________________ Zope-Dev maillist - Zope-Dev@zope.org http://lists.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope )
Oh I see... objects don't get __del__ or manage_beforeDelete called on them when the ZODB is shut down, this only happens when they're explicitly deleted. This is the wonder of transparent persistence :-) If you want things to happen only at Zope start and shutdown, I've had some success using an __init__.py that does things in an otherwise blank product in combination with the setting of a Python sys.exitfunc. The following __init__.py in an otherwise blank Product directory sends an email when Zope is stopped or started: import os, sys, popen2, socket prefix = "StartStopNotifier:" def stop_hook(): mailout(user, prefix, host, "Zope dev portal stop") if callable(existing_exitfunc): existing_exitfunc() def start_hook(): mailout(user, prefix, host, "Zope dev portal start") def mailout(user, prefix, host, subject): cmd="/bin/mail %s -s '%s %s %s' < /dev/null" % (user,prefix,host,subject) popen2.popen2(cmd) user = os.environ.get('STARTSTOPNOTIFY', None) if user is not None: host = socket.gethostname() existing_exitfunc = getattr(sys, 'exitfunc', None) sys.exitfunc = stop_hook start_hook() andym@ActiveState.com wrote:
I was hoping to have this method fired Zope is shut down, restarted etc and not call it implicitly. The theory being if this object is cached it will have to be unloaded at some point?
Ive used manage_beforeDelete() elsewhere and it works fine when Im destroying an object whilst ZODB is still running.
Thanks.
-- Chris McDonough Digital Creations, Publishers of Zope http://www.zope.org
Wow thanks. I'll see what I can do. I can think of a whole bunch of uses for that. ----- Original Message ----- From: "Chris McDonough" <chrism@digicool.com> To: <andym@ActiveState.com> Cc: <zope-dev@zope.org> Sent: Monday, September 18, 2000 3:10 PM Subject: Re: [Zope-dev] __del__
Oh I see... objects don't get __del__ or manage_beforeDelete called on them when the ZODB is shut down, this only happens when they're explicitly deleted. This is the wonder of transparent persistence :-)
If you want things to happen only at Zope start and shutdown, I've had some success using an __init__.py that does things in an otherwise blank product in combination with the setting of a Python sys.exitfunc. The following __init__.py in an otherwise blank Product directory sends an email when Zope is stopped or started:
import os, sys, popen2, socket
prefix = "StartStopNotifier:"
def stop_hook(): mailout(user, prefix, host, "Zope dev portal stop") if callable(existing_exitfunc): existing_exitfunc()
def start_hook(): mailout(user, prefix, host, "Zope dev portal start")
def mailout(user, prefix, host, subject): cmd="/bin/mail %s -s '%s %s %s' < /dev/null" % (user,prefix,host,subject) popen2.popen2(cmd)
user = os.environ.get('STARTSTOPNOTIFY', None) if user is not None: host = socket.gethostname() existing_exitfunc = getattr(sys, 'exitfunc', None) sys.exitfunc = stop_hook start_hook()
andym@ActiveState.com wrote:
I was hoping to have this method fired Zope is shut down, restarted etc
and
not call it implicitly. The theory being if this object is cached it will have to be unloaded at some point?
Ive used manage_beforeDelete() elsewhere and it works fine when Im destroying an object whilst ZODB is still running.
Thanks. -- Chris McDonough Digital Creations, Publishers of Zope http://www.zope.org
participants (2)
-
Andy McKay -
Chris McDonough