Zope Product Reload
I understand its possible to reload a module with python. Theoretically, it should be possible to reload a Zope Product without restarting Zope. I would like to develop a Product/Patch/External Method that would allow this. After a couple hours of research, I have more questions than answers. If anyone has looked at this, I would appreciate some insight. Here are a few questions. 1. It appears that Zope puts in its own __import__ and reload hooks, is this correct? Why does Zope do this? 2. Just setting up a simple method, such as the following doesn't work either. import Products from CStringIO import StringIO def manage_reload(self, product_name, REQUEST=None): """Reload a Product without restarting Zope""" if hasattr(Products, product_name): product=getattr(Products,product_name) else: return 'Product not found' modules=sys.modules try: reload(product) except: f=StringIO() traceback.print_exc(100,f) f=f.getvalue() try: modules[pname].__import_error__=f except: pass The strange thing about this method is that the module DOES get reloaded, but the new module doesn't appear to get used. Very puzzling! Mostly, I am wondering if anyone else has tried or thought about this problem. Developing products can take many, many iterations, and I am just tired of waiting the three or four seconds for Zope to restart. Drew
Hmmm... I think the reload does reload the module, so that any *new* instances created from classes in that module will use the new code *but* any old instances (in memory), will still refer to the old class definitions. You will need to flush all these from memory and re-instantiate them to get them to use the new module... or somehow go through all the instances and replace their __class__ with the new version. -steve
"Andrew" == Andrew Lahser <andrew@eventera.com> writes:
Andrew> I understand its possible to reload a module with python. Andrew> Theoretically, it should be possible to reload a Zope Andrew> Product without restarting Zope. Andrew> I would like to develop a Product/Patch/External Method Andrew> that would allow this. After a couple hours of research, I Andrew> have more questions than answers. If anyone has looked at Andrew> this, I would appreciate some insight. Andrew> Here are a few questions. Andrew> 1. It appears that Zope puts in its own __import__ and Andrew> reload hooks, is this correct? Why does Zope do this? Andrew> 2. Just setting up a simple method, such as the following Andrew> doesn't work either. Andrew> import Products from CStringIO import StringIO Andrew> def manage_reload(self, product_name, REQUEST=None): Andrew> """Reload a Product without restarting Zope""" if Andrew> hasattr(Products, product_name): Andrew> product=getattr(Products,product_name) else: return Andrew> 'Product not found' modules=sys.modules try: Andrew> reload(product) except: f=StringIO() Andrew> traceback.print_exc(100,f) f=f.getvalue() try: Andrew> modules[pname].__import_error__=f except: pass Andrew> The strange thing about this method is that the module Andrew> DOES get reloaded, but the new module doesn't appear to Andrew> get used. Andrew> Very puzzling! Andrew> Mostly, I am wondering if anyone else has tried or thought Andrew> about this problem. Developing products can take many, Andrew> many iterations, and I am just tired of waiting the three Andrew> or four seconds for Zope to restart. Andrew> Drew Andrew> _______________________________________________ Zope-Dev Andrew> maillist - Zope-Dev@zope.org Andrew> http://lists.zope.org/mailman/listinfo/zope-dev ** No Andrew> cross posts or HTML encoding! ** (Related lists - Andrew> http://lists.zope.org/mailman/listinfo/zope-announce Andrew> http://lists.zope.org/mailman/listinfo/zope )
I played with this a while back and had good luck when I got the reference to the object by importing it rather than with getattr.. i.e. import( product ) reload( product ) this reloaded the module..
participants (3)
-
Andrew Lahser -
Stefan Kuzminski -
Steve Spicklemire