Skip to content

Instantly share code, notes, and snippets.

@etcimon
Created July 21, 2015 15:35
Show Gist options
  • Save etcimon/7fdd98c87a4793f6621b to your computer and use it in GitHub Desktop.
Save etcimon/7fdd98c87a4793f6621b to your computer and use it in GitHub Desktop.
#!/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