Re: [Zope-dev] The Application object
Yves-Eric Martin wrote: Shane Hathaway [EMAIL PROTECTED] wrote: You *must* remember to close the connection: app._p_jar.close() This is not mentionned in the above document, so I was doing without so far, and did not run into any problem. Now that I see it, I believe this is the Right Thing to Do and will include it in the release. But since you put an emphasis on its being required, can you tell us what evil things may happen if you don't close the connection? (Consuming ressources?) That's correct. Only a certain number of connections are allowed at a time. Currently, as the "app" object falls out of scope it should close the connection automatically, but that may not always be the case IMHO. BTW if you're using this technique, be sure you're not opening two connections in one thread. It can prove hazardous. Shane ___ Zope-Dev maillist - [EMAIL PROTECTED] 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 )
RE: [Zope-dev] The Application object
I'm not sure I understand. What is AppSingleton? What does the Instance() method do? -Original Message- From: Jeff K. Hoffman [mailto:[EMAIL PROTECTED]] Sent: Monday, July 17, 2000 11:54 AM To: [EMAIL PROTECTED] Subject: [Zope-dev] The Application object Hello, What is the easiest way for me to get ahold of the Application object at run-time? I am writing a Product that needs to access some things in the Control_Panel, and need the app object to get there. I know how to do it given a reference to an object in the ZODB (getPhysicalRoot(), etc.), but need a way to do it given no references. I need something like: import AppSingleton app = AppSingleton.Instance() app.Control_Panel.blah --Jeff --- Jeff K. Hoffman 704.849.0731 x108 Chief Technology Officer mailto:[EMAIL PROTECTED] Going Virtual, L.L.C. http://www.goingv.com/ ___ Zope-Dev maillist - [EMAIL PROTECTED] 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 ) ___ Zope-Dev maillist - [EMAIL PROTECTED] 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 )
RE: [Zope-dev] The Application object
On Mon, 17 Jul 2000, Chris McDonough wrote: I'm not sure I understand. What is AppSingleton? What does the Instance() method do? Sorry I wasn't clear enough. The Singleton is a design pattern from the Gang of Four book that fits this situation well. It is a class that is meant to control access to the one and only instance of a global variable. I was just using that as a frame of reference, though; Zope has no such class for the Application object, or I wouldn't be writing this message. I just need some way of getting at the one and only Application object at run-time. Something like: from Globals import app myOb = app.Control_Panel.Products.MyProduct.MyZClass('foo') ... Given a reference to an object in the ZODB, I can do this via: app = self.getPhysicalRoot() myOb = app.Control_Panel.Products.MyProduct.MyZClass('foo') But, this does not work from methods like __init__, or __setstate__, where we do not have a physical location in the ZODB, yet. I just need a reference to the app object. I know the answer has to be simple, but I can't find it. --Jeff --- Jeff K. Hoffman 704.849.0731 x108 Chief Technology Officer mailto:[EMAIL PROTECTED] Going Virtual, L.L.C. http://www.goingv.com/ ___ Zope-Dev maillist - [EMAIL PROTECTED] 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 )
RE: [Zope-dev] The Application object
Sorry I wasn't clear enough. The Singleton is a design pattern from the Gang of Four book that fits this situation well. It is a class that is meant to control access to the one and only instance of a global variable. I was just using that as a frame of reference, though; Zope has no such class for the Application object, or I wouldn't be writing this message. Oh, ok, sorry, hard to tell intent from actual code. :-) I just need some way of getting at the one and only Application object at run-time. Something like: from Globals import app myOb = app.Control_Panel.Products.MyProduct.MyZClass('foo') ... Given a reference to an object in the ZODB, I can do this via: app = self.getPhysicalRoot() myOb = app.Control_Panel.Products.MyProduct.MyZClass('foo') But, this does not work from methods like __init__, or __setstate__, where we do not have a physical location in the ZODB, yet. Ah, I see the problem. I'm afraid I don't know the answer. I generally use the manage_afterAdd and manage_beforeDelete methods to do things like this. I suppose you could pass the root object into the constructor. __setstate__... well. Err... Anybody else? ___ Zope-Dev maillist - [EMAIL PROTECTED] 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 )
Re: [Zope-dev] The Application object
Chris McDonough wrote: Sorry I wasn't clear enough. The Singleton is a design pattern from the Gang of Four book that fits this situation well. It is a class that is meant to control access to the one and only instance of a global variable. I was just using that as a frame of reference, though; Zope has no such class for the Application object, or I wouldn't be writing this message. Oh, ok, sorry, hard to tell intent from actual code. :-) I just need some way of getting at the one and only Application object at run-time. Something like: from Globals import app myOb = app.Control_Panel.Products.MyProduct.MyZClass('foo') ... Given a reference to an object in the ZODB, I can do this via: app = self.getPhysicalRoot() myOb = app.Control_Panel.Products.MyProduct.MyZClass('foo') But, this does not work from methods like __init__, or __setstate__, where we do not have a physical location in the ZODB, yet. Ah, I see the problem. I'm afraid I don't know the answer. I generally use the manage_afterAdd and manage_beforeDelete methods to do things like this. I suppose you could pass the root object into the constructor. __setstate__... well. Err... Anybody else? The way to get the root application object is to open a connection to the ZODB and get the 'Application' object from the list of root objects. There is an easy shortcut: import Zope app = Zope.app() app now refers to a *copy* of the root Application object. When you're done modifying it and its descendants you have to commit or abort the transaction. get_transaction().commit() (or abort()) This gives you all kinds of benefits like undo and elimination of threading conflicts. You *must* remember to close the connection: app._p_jar.close() Shane ___ Zope-Dev maillist - [EMAIL PROTECTED] 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 )
Re: [Zope-dev] The Application object
On Mon, 17 Jul 2000, Shane Hathaway wrote: The way to get the root application object is to open a connection to the ZODB and get the 'Application' object from the list of root objects. There is an easy shortcut: import Zope app = Zope.app() app now refers to a *copy* of the root Application object. Yeehaw, that worked! I was so close. :-) When you're done modifying it and its descendants you have to commit or abort the transaction. [snip] Do I need to commit or abort even if I don't make changes to the application object? The only thing I need it for is to get to the Control_Panel; I am instantiating ZClass instances in the constructor of a Python class, i.e.: class MyClass: def __init__(self, id, title=''): import Zope app = Zope.app() ob = app.Control_Panel.Products.MyProduct.MyZClass('newId') ob.id = 'newId' self._setObject('newId', ob) # Do I need a get_transaction().abort() here? Will that not abort # the wrong transaction? app._p_jar.close() ... This gives you all kinds of benefits like undo and elimination of threading conflicts. [snip] Good stuff. Thanks, Shane. Shane --Jeff --- Jeff K. Hoffman 704.849.0731 x108 Chief Technology Officer mailto:[EMAIL PROTECTED] Going Virtual, L.L.C. http://www.goingv.com/ ___ Zope-Dev maillist - [EMAIL PROTECTED] 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 )
RE: [Zope-dev] The Application object
So it's kosher then to reimport the Zope module and use app() in a constructor method, Shane? I was always afraid it would do something horrible. -Original Message- From: Jeff K. Hoffman [mailto:[EMAIL PROTECTED]] Sent: Monday, July 17, 2000 1:11 PM To: Shane Hathaway Cc: Chris McDonough; 'Jeff K. Hoffman'; [EMAIL PROTECTED] Subject: Re: [Zope-dev] The Application object On Mon, 17 Jul 2000, Shane Hathaway wrote: The way to get the root application object is to open a connection to the ZODB and get the 'Application' object from the list of root objects. There is an easy shortcut: import Zope app = Zope.app() app now refers to a *copy* of the root Application object. Yeehaw, that worked! I was so close. :-) When you're done modifying it and its descendants you have to commit or abort the transaction. [snip] Do I need to commit or abort even if I don't make changes to the application object? The only thing I need it for is to get to the Control_Panel; I am instantiating ZClass instances in the constructor of a Python class, i.e.: class MyClass: def __init__(self, id, title=''): import Zope app = Zope.app() ob = app.Control_Panel.Products.MyProduct.MyZClass('newId') ob.id = 'newId' self._setObject('newId', ob) # Do I need a get_transaction().abort() here? Will that not abort # the wrong transaction? app._p_jar.close() ... This gives you all kinds of benefits like undo and elimination of threading conflicts. [snip] Good stuff. Thanks, Shane. Shane --Jeff --- Jeff K. Hoffman 704.849.0731 x108 Chief Technology Officer mailto:[EMAIL PROTECTED] Going Virtual, L.L.C. http://www.goingv.com/ ___ Zope-Dev maillist - [EMAIL PROTECTED] 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 )
Re: [Zope-dev] The Application object
On Mon, Jul 17, 2000 at 12:21:42PM -0400, Jeff K. Hoffman wrote: On Mon, 17 Jul 2000, Chris McDonough wrote: I'm not sure I understand. What is AppSingleton? What does the Instance() method do? Sorry I wasn't clear enough. The Singleton is a design pattern from the Gang of Four book that fits this situation well. It is a class that is meant to control access to the one and only instance of a global variable. I was just using that as a frame of reference, though; Zope has no such class for the Application object, or I wouldn't be writing this message. I just need some way of getting at the one and only Application object at run-time. Something like: from Globals import app myOb = app.Control_Panel.Products.MyProduct.MyZClass('foo') ... Given a reference to an object in the ZODB, I can do this via: app = self.getPhysicalRoot() myOb = app.Control_Panel.Products.MyProduct.MyZClass('foo') But, this does not work from methods like __init__, or __setstate__, where we do not have a physical location in the ZODB, yet. I just need a reference to the app object. I know the answer has to be simple, but I can't find it. See the __init__.py method of ZScheduler, which can be found on Zope.org. ZScheduler uses a Singleton as well. -- Martijn Pieters | Software Engineermailto:[EMAIL PROTECTED] | Digital Creations http://www.digicool.com/ | Creators of Zope http://www.zope.org/ | ZopeStudio: http://www.zope.org/Products/ZopeStudio - ___ Zope-Dev maillist - [EMAIL PROTECTED] 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 )
Re: [Zope-dev] The Application object
On Mon, 17 Jul 2000 12:50:27 -0400 Shane Hathaway [EMAIL PROTECTED] wrote: import Zope app = Zope.app() get_transaction().commit() I am doing just that in the next version of zzLocale (Zope interface internationalization product) I was about to release. I figured it out from the "Zope Debugging" doc (http://www.zope.org/Documentation/Misc/DEBUGGING.txt), but: You *must* remember to close the connection: app._p_jar.close() This is not mentionned in the above document, so I was doing without so far, and did not run into any problem. Now that I see it, I believe this is the Right Thing to Do and will include it in the release. But since you put an emphasis on its being required, can you tell us what evil things may happen if you don't close the connection? (Consuming ressources?) -- Yves-Eric Martin Digital Garage Inc. [EMAIL PROTECTED] ___ Zope-Dev maillist - [EMAIL PROTECTED] 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 )