transaction abort with multiple threads

Joachim Worringen <[email protected]> Wed, 19 May 2010 10:52:49 +0200
Newsgroups gmane.comp.python.db.psycopg.devel
Organization IAT GmbH
Message-ID <[email protected]>
Greetings,

I'm using psycopg2 2.2.1 with Postgresql 8.4. Within my Python 
application, I'm creating threads via threading.Thread(), passing the 
same connection to each of them. Each threads creates its own cursor then.

Exception in thread Thread-11:
Traceback (most recent call last):
   File "/usr/lib64/python2.6/threading.py", line 525, in __bootstrap_inner
     self.run()
   File "/usr/lib64/python2.6/threading.py", line 477, in run
     self.__target(*self.__args, **self.__kwargs)
   File "/home/joachim/bin/pb_operators.py", line 911, in store_data
     self._aggregate_runs(db, output_table)
   File "/home/joachim/bin/pb_operators.py", line 506, in _aggregate_runs
     "#* DEBUG: creating new data set (paramters):" )
   File "/home/joachim/bin/pb_common.py", line 659, in sqlexe
     crs.execute(cmd, args)
InternalError: SET TRANSACTION ISOLATION LEVEL must be called before any 
query

The queries of all other threads are aborted at this point, which is 
expected.

Do I need to set autocommit-mode in this case, and if yes, will this 
affect performance (each thread may read and insert millions of elements)?

  thanks, Joachim