Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- """
- Created on Sun Nov 13 00:00:06 2016
- @author: ergo
- """
- import select
- import psycopg2
- import psycopg2.extensions
- import threading
- def notify(conn):
- print "Waiting for notifications on channel 'cats'"
- while True:
- if select.select([conn],[],[],1) != ([],[],[]):
- conn.poll()
- while conn.notifies:
- notify = conn.notifies.pop(0)
- print "Got NOTIFY:", notify.pid, notify.channel, notify.payload
- print "Must refresh cache"
- conn = psycopg2.connect("host=<host> dbname=<dbname> user=<user> password=<password>")
- conn.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)
- curs = conn.cursor()
- curs.execute("LISTEN cats;")
- t = threading.Thread(target=notify, args=(conn,))
- t.start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement