Created
July 21, 2015 15:35
-
-
Save etcimon/7fdd98c87a4793f6621b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import select | |
import psycopg2 | |
import psycopg2.extensions | |
dbc = psycopg2.connect(database='depesz', host='127.0.0.1', port=5920) | |
dbc.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT) | |
cur = dbc.cursor() | |
cur.execute('LISTEN new_user') | |
while 1: | |
if not select.select([dbc], [], [], 5) == ([], [], []): | |
dbc.poll() | |
while dbc.notifies: | |
notify = dbc.notifies.pop() | |
print "new_user %s, backed: %d" % (notify.payload, notify.pid) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment