Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #51779 > unrolled thread
| Started by | Ian Kelly <ian.g.kelly@gmail.com> |
|---|---|
| First post | 2013-08-01 19:22 -0600 |
| Last post | 2013-08-01 19:22 -0600 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Best practice for connections and cursors Ian Kelly <ian.g.kelly@gmail.com> - 2013-08-01 19:22 -0600
| From | Ian Kelly <ian.g.kelly@gmail.com> |
|---|---|
| Date | 2013-08-01 19:22 -0600 |
| Subject | Re: Best practice for connections and cursors |
| Message-ID | <mailman.103.1375406614.1251.python-list@python.org> |
On Thu, Aug 1, 2013 at 6:49 PM, Dennis Lee Bieber <wlfraed@ix.netcom.com> wrote: > On Thu, 1 Aug 2013 15:05:08 +0000, "Joseph L. Casale" > <jcasale@activenetwerx.com> declaimed the following: > >> >>As the module opens a connection, wherever I import it I call a commit against >>the connection after invoking any methods that insert or change data. >> > > You probably should NOT be opening connections /during/ the import > operation... For one thing, if it is a module level connection, multiple > imports are replacing earlier connections with their fresh one. That's not true. Multiple imports of the same module will only execute the module-level code the first time. I agree though that simply importing the module should not trigger a connection to be opened. That should be an explicit step. Speaking to the OP: personally, I don't like the approach of putting data access methods at the module level to begin with. I'd rather use a class. Just because it makes sense to have a singleton connection now doesn't mean it will always make sense as your application grows. In fact, the conflict you describe where one cursor is interfering with another cursor suggests that you may already be at the point of needing multiple connections. The operation that is creating a temp table and messing things up should ideally be pulling an unused connection from a pool, so as to avoid potentially contaminating a connection that may already be in use elsewhere in the code.
Back to top | Article view | comp.lang.python
csiph-web