python async with psycopg2 - Mailing list pgsql-general

From Rita
Subject python async with psycopg2
Date
Msg-id CAOF-Kfh1P9eanS0hecw_E9Awdsmn3b4uYpnV5SdL8Xz31U2rBw@mail.gmail.com
Whole thread Raw
Responses Re: python async with psycopg2
List pgsql-general
I am trying to listen to multiple channels thru pg_notify mechanism.

select pg_notify('mychan0',foo');
select pg_notify('mychan'1,'bar');

In python I have something like this

import select,time
import psycopg2
import psycopg2.extensions
from psycopg2.extras import wait_select

DSN="dbname=mydb user=user host=localhost"

def main():

    conn = psycopg2.connect(DSN,async_=True)
    wait_select(conn)
    curs = conn.cursor()
    curs.execute("LISTEN mychan0;")
    #curs.execute("LISTEN mychan1;") #fails!
    wait_select(conn)
    while True:
        wait_select(conn)
        while conn.notifies:
            print("Notify: %s"%conn.notifies.pop().payload)
            time.sleep(1)
    conn.close()

I keep getting 

psycopg2.ProgrammingError: execute cannot be used while an asynchronous query is underway

I prefer to stick with psycopg2 library instead of a wrapper. 
What am I doing wrong?

--
--- Get your facts first, then you can distort them as you please.--

pgsql-general by date:

Previous
From: Ailleen Pace
Date:
Subject: DB Authentication with Label Security
Next
From: Daniele Varrazzo
Date:
Subject: Re: python async with psycopg2