Product event when zope restarts
Hello all! I have been developing a Zope Product that basically reads in a file and shows it in zope. The problem is that when the file is updated in file system, that is not updated in zope. I do not want it to read the file every time it is accessed in zope. Refreshing it every time the zope restarts seems to be the solution. So I was wondering if there is a function that will be executed when zope restarts. Thanx.
Have you looked at the ExtFile object? cheers, Chris
Jan wrote:
Hello all!
I have been developing a Zope Product that basically reads in a file and shows it in zope. The problem is that when the file is updated in file system, that is not updated in zope. I do not want it to read the file every time it is accessed in zope. Refreshing it every time the zope restarts seems to be the solution.
So I was wondering if there is a function that will be executed when zope restarts.
Thanx.
Have you looked at the ExtFile object?
cheers,
Chris Yes. As I wrote, the product BASICALLY does this. Actually it reads the file, parses it and shows it's contents in the properties tab. When I write something like <dtml-var "myProduct.property1"> then I can access a part of the file.
Jan wrote:
Hello all!
I have been developing a Zope Product that basically reads in a file and
shows
it in zope. The problem is that when the file is updated in file system, that is not updated in zope. I do not want it to read the file every time it is accessed in zope. Refreshing it every time the zope restarts seems to be the solution.
So I was wondering if there is a function that will be executed when zope restarts.
Thanx.
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Hi Jan, what about using stat() on the file to check if it has changed and reread in that event? Make sure you reread only for the current access. Regards Tino --On Donnerstag, 10. Mai 2001 16:40 +0300 Jan <jan@itmeedia.ee> wrote:
Have you looked at the ExtFile object?
cheers,
Chris Yes. As I wrote, the product BASICALLY does this. Actually it reads the file, parses it and shows it's contents in the properties tab. When I write something like <dtml-var "myProduct.property1"> then I can access a part of the file.
Jan wrote:
Hello all!
I have been developing a Zope Product that basically reads in a file and
shows
it in zope. The problem is that when the file is updated in file system, that is not updated in zope. I do not want it to read the file every time it is accessed in zope. Refreshing it every time the zope restarts seems to be the solution.
So I was wondering if there is a function that will be executed when zope restarts.
Thanx.
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
That is a very good idea, only there seems to be no function where I could do so.. The properties of my product are accessed directly like <dtml-var "myProduct.property1"> so no function is executed. The getProperty is only executed when watching the property list. :(
what about using stat() on the file to check if it has changed and reread in that event? Make sure you reread only for the current access.
Yes. As I wrote, the product BASICALLY does this. Actually it reads the file, parses it and shows it's contents in the properties tab. When I write something like <dtml-var "myProduct.property1"> then I can access a part of the file.
Hi Jan, With python, you can override subobjects access. For example, you can give your class a __getattr__() method to call a function every time an attribute is accessed. HTH Tino Wildenhain PS: the other approach would be to send the file each time it is generated into zope from the application which generates the file --On Donnerstag, 10. Mai 2001 17:44 +0300 Jan <jan@itmeedia.ee> wrote:
That is a very good idea, only there seems to be no function where I could do so.. The properties of my product are accessed directly like <dtml-var "myProduct.property1"> so no function is executed. The getProperty is only executed when watching the property list. :(
what about using stat() on the file to check if it has changed and reread in that event? Make sure you reread only for the current access.
Yes. As I wrote, the product BASICALLY does this. Actually it reads the file, parses it and shows it's contents in the properties tab. When I write something like <dtml-var "myProduct.property1"> then I can access a part of the file.
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Jan wrote:
Hello all!
I have been developing a Zope Product that basically reads in a file and shows it in zope. The problem is that when the file is updated in file system, that is not updated in zope. I do not want it to read the file every time it is accessed in zope. Refreshing it every time the zope restarts seems to be the solution.
So I was wondering if there is a function that will be executed when zope restarts.
Thanx.
What is the problem with repeatedly reading the file? The OS will cache it if it is accessed frequently anyway. If you must here is what I would do: Use two volatile variables to store the mod date and the data like: _v_mod _v_data Then stat the file when it is accessed and see if its date differs from _v_mod (if it has already been accessed). If not, return _v_data. Otherwise read the file, return the data and store it into _v_data and the mod date in _v_mod. hth, -- | Casey Duncan | Kaivo, Inc. | cduncan@kaivo.com `------------------>
If you must here is what I would do:
Use two volatile variables to store the mod date and the data like:
_v_mod _v_data
Then stat the file when it is accessed and see if its date differs from _v_mod (if it has already been accessed). If not, return _v_data. Otherwise read the file, return the data and store it into _v_data and the mod date in _v_mod.
hth, ---from ZDG-----
The second rule is that all object attributes that begin with _v_ are "volatile" and are not saved to the database. This means that as long as the persistent object is in Zope memory cache, volatile attributes can be used. When the object is deactivated (removed from memory) volatile attributes are thrown away. Volatile attributes are useful for data that is good to cache for a while but can often be thrown away and easily recreated. File connections, cached calculations, rendered templates, all of these kinds of things are useful applications of volatile attributes. --------------------------- so, we may lose _v_mod, _v_data. what if we store these vars to be nonvolatile. what will that do? is that bad design? does this fall in the "good to cache for a while but can often be thrown away and easily recreated" department? this is something that i don't really understand. when to use _v_, and when not to. thanks
Hook sys.exitfunc to have something happen every time Zope is shut down. ----- Original Message ----- From: Jan To: zope@zope.org Sent: Thursday, May 10, 2001 9:26 AM Subject: [Zope] Product event when zope restarts Hello all! I have been developing a Zope Product that basically reads in a file and shows it in zope. The problem is that when the file is updated in file system, that is not updated in zope. I do not want it to read the file every time it is accessed in zope. Refreshing it every time the zope restarts seems to be the solution. So I was wondering if there is a function that will be executed when zope restarts. Thanx.
If you really need to do that doesnt __init__ get called at every restart? You could in theory (I dont know how though do something there). Reading from a file is not a big hit, I would go with Casey's suggestion and cache when it was last changed. Cheers. -- Andy McKay.
participants (7)
-
Andy McKay -
bak -
Casey Duncan -
Chris McDonough -
Chris Withers -
Jan -
Tino Wildenhain