Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #51773
| From | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
|---|---|
| Subject | Re: Best practice for connections and cursors |
| Date | 2013-08-01 20:49 -0400 |
| Organization | IISS Elusive Unicorn |
| References | <assp.0925de7e70.719ac7ca4c274c4c884b809e5abd887c@exch.activenetwerx.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.102.1375404608.1251.python-list@python.org> (permalink) |
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 comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Best practice for connections and cursors Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-08-01 20:49 -0400
csiph-web