Re: user's process shows as "idle in transaction"

Federico Di Gregorio <fog-NGVKUo/i/[email protected]>
Newsgroups gmane.comp.python.db.psycopg.devel
Organization initd.org
Message-ID <1246343253.4577.3.camel@erin>
Il giorno lun, 29/06/2009 alle 12.26 -0700, Janet Jacobsen ha scritto:
[snip]
> The user told me that he does not close the database connection
> after the fetchall - instead he has a Python sleep command, so that 
> he is checking the database every 60 s to see whether new entries
> have been added to a given table
> His code is part of an analysis pipeline, whereas the part of the
> database that I work on is loading processed data into the
> database.
> Is there something missing from his code sample, like a commit or
> a set_isolation_level, that if added would prevent the "idle in
> transaction" from happening?  

The user is wrong and you're right, the "idle in transaction" can be
avoided by both a commit() (or rollback()) before going to sleep or by
setting the transaction mode to "autocommit":

conn.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)

Hope this helps,
federico

-- 
Federico Di Gregorio                         http://people.initd.org/fog
Debian GNU/Linux Developer                                [email protected]
INIT.D Developer                                           fog-NGVKUo/i/[email protected]
                      Sei una bergogna. Vergonga. Vergogna. -- Valentina

_______________________________________________
Psycopg mailing list
Psycopg-IAPFreCvJWPBWskQ1e/[email protected]
http://lists.initd.org/mailman/listinfo/psycopg
signature.asc (application/pgp-signature, 197 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEABECAAYFAkpJsFAACgkQvcCgrgZGjevVqwCfVreF1jx19icupNhf484S72Wr
Q1MAoKEHxvW1GGwaDz0vdd6q/VRF5o3K
=z27+
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.