Mario Frasca wrote: > On 2006-0925 10:27:16, M.-A. Lemburg wrote: >> Sounds reasonable, though strictly speaking, the with-container >> is not necessary, since cursors and connections will close themselves >> when garbage collected, ie. as soon as they go out of scope. > > this (garbage collected as soon as they go out of scope) is more > implementation dependent than absolutely true... > > the garbage collector is activated "when it feels like", and will > collect all garbage, or maybe just as much garbage as it is given time > to..., again depending on the implementation and the situation.
This is only true for Jython and perhaps IronPython (I don't know how objects are managed there). In CPython, an object is GCed as soon as the reference count falls to zero. The Python garbage collector is only needed for situations where you've created circular references keeping a closed set of objects alive. The Python GC is run every now and then or explicitly by calling gc.collect(). > I don't know how much determinism is desired, but the with construct can > introduce quite a lot of it. > >> In some cases it may not even be desirable to close the cursor or >> connection, since this prevents effective debugging (the traceback >> passed to outer scopes will contain a reference to the cursor and >> connection, keeping them open). > > in this case the user would not use the with construct and take care > that the connection / cursor do not get garbage collected... > > as usual, getting lost in details. > > I really like this new construct and taking advantage of it seems to me > the right thing to do. No objections there :-) It certainly saves a few try-finally enclosures. -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Sep 25 2006) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! :::: _______________________________________________ DB-SIG maillist - DB-SIG@python.org http://mail.python.org/mailman/listinfo/db-sig