How to prevent the error " ProgrammingError: execute cannot be used while an asynchronous query is underway "? From the docs it says that I should use psycopg2.extras.wait_select if Im uses coroutine support like gevent., But Im still getting this error when Im using it. Ive highlighted the Im error included in the 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 * FROM 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) ])
source share