psycopg2 - Python error: execute cannot be used while an asynchronous query is underway -


how prevent error “programmingerror: execute cannot used while asynchronous query underway”? docs says should use psycopg2.extras.wait_select if i’m using coroutine support gevent., i’m still error when i’m using it. i’ve isolated error i’m getting in snippet below.

con = psycopg2.connect(database=database_name, user=database_username)  def execute_query(cur, query, params):     psycopg2.extras.wait_select(con)     cur.execute(query, params)     psycopg2.extras.wait_select(con)     rows = cur.fetchall()     print rows[0]  cur = con.cursor() query = "select * mytable" gevent.joinall([      gevent.spawn(execute_query, cur, query, none),      gevent.spawn(execute_query, cur, query, none),      gevent.spawn(execute_query, cur, query, none),      gevent.spawn(execute_query, cur, query, none) ]) 

you trying more 1 transaction simultaneously on single connection. psycopg documentation says not thread safe , lead error. see under asynchronous support , support coroutine libraries

one possible solution use 1 database connection, each 1 cursor, per coroutine (4 distinct connections , cursors in case).


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -