Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #102784 > unrolled thread
| Started by | "Frank Millman" <frank@chagford.com> |
|---|---|
| First post | 2016-02-11 07:28 +0200 |
| Last post | 2016-02-11 07:28 +0200 |
| 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: Handling transactions in Python DBI module "Frank Millman" <frank@chagford.com> - 2016-02-11 07:28 +0200
| From | "Frank Millman" <frank@chagford.com> |
|---|---|
| Date | 2016-02-11 07:28 +0200 |
| Subject | Re: Handling transactions in Python DBI module |
| Message-ID | <mailman.31.1455168546.22075.python-list@python.org> |
"Chris Angelico" wrote in message news:CAPTjJmphJvtCKUB6Qr-vp_1epEWxBgQxmfKEPMOhQp3pAPGG+A@mail.gmail.com... > > When I advise my students on basic databasing concepts, I recommend > this structure: > > conn = psycopg2.connect(...) > > with conn, conn.cursor() as cur: > cur.execute(...) > Does this automatically issue a 'conn.commit()' on exit? I have found that this is important, for the following reason. If you issue a bare SELECT to PostgreSQL, it executes it without creating any locks. However, if it is inside a transaction, it does create a lock (I forget exactly which one). Because psycopg2 silently executes 'BEGIN TRANSACTION', your SELECTs always happen inside a transaction whether you specify it or not. If you do not issue a conn.commit(), the locks do not get cleared. Frank
Back to top | Article view | comp.lang.python
csiph-web