SV: SV: [ZODB-Dev] Flush
Magnus Heino
magnus.heino@pleon.sigma.se
Thu, 31 Jan 2002 19:49:38 +0100
> >> >Can I make the ZODB not flush an object out from memory once it
> >> >has been loaded from disk?
> >>
> >> Using the C API yes. Look at PER_PREVENT_DEACTIVATION in
> >> cPersistence.h
> >>
> >> You cant do this from python. Why do you want to?
>
> MH> Because the object does start_new_thread in __setstate__, and
> MH> _setstate__ is called every now and then... :-P
>
> That's enough of answer for me to worry about what you're doing :-).
Hum. ;-)
> I'm not sure I understand why you're trying to accomplish, but I think
> you need to add more sophistication to your __setstate__().
>
> I believe part of the contract you sign up for as a Persistent object
> is that you agree to let your data manager (connection/ZODB) be
> responsible for deciding when to load and unload the object from
> memory. In other words, ZODB decides when to call __getstate__() and
> __setstate__(). It doesn't provide any direct mechanism for the
> programmer to control when they get called.
>
> What is the thread doing in __setstate__()?
Ive got a persistent object being published by ZPublisher. This object has a
start method that does start_new_thread(self.method, ()). self.method does
not terminate before a stop method is called. While running, it performs
come calculations. This way I can view what the thread is doing, by browsing
with ZPublisher. However, it seems as if the object is flushed from memory,
leaving a thread running... later on when I call some method on the object,
it is loaded from disk into memory again. In setstate, I look at a attribute
self.__isRunning and calls start_new_thread(self.method, ()) if it was
running when before. This way the thread will start if it was running when
the app was closed. But also if the object was flushed... :-P
Im running ZServer with one thread. Its not Zope, just some parts of it.
This was the reason I asked this a while ago too,
http://lists.zope.org/pipermail/zope3-dev/2002-January/000408.html
With python2.2 you can do "class foo(Persistent, Thread):"... but I guess
the same applies there, this is something that you shouldnt be doing? :-P
This currently is with python 2.1.2 though...
Thanks!
/Magnus