Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #51773 > unrolled thread
| Started by | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
|---|---|
| First post | 2013-08-01 20:49 -0400 |
| Last post | 2013-08-01 20:49 -0400 |
| 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 Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-08-01 20:49 -0400
| From | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
|---|---|
| Date | 2013-08-01 20:49 -0400 |
| Subject | Re: Best practice for connections and cursors |
| Message-ID | <mailman.102.1375404608.1251.python-list@python.org> |
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 is -- do NOT do:
-=-=-=-=- (imported module)
...
theCon = db.connection(database)
...
-=-=-=-=-
Instead, use something like
-=-=-=-=-
...
def initialize():
global theCon
theCon = db.connection(database)
...
-=-=-=-=-
and have only one importer invoke
theModule.initialize()
which should take place after all imports have been resolved.
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/
Back to top | Article view | comp.lang.python
csiph-web