Guest User

Untitled

a guest
Apr 25th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. import select
  2. import psycopg2
  3. import psycopg2.extensions
  4. import subprocess
  5. from halo import Halo
  6. conn = psycopg2.connect(dbname='pg_pubsub', user='postgres', host='localhost', password='123456')
  7. conn.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)
  8. curs = conn.cursor()
  9. curs.execute("LISTEN mensagens;")
  10. spinner = Halo(text='Aguardando as notificações', spinner='dots')
  11. spinner.start()
  12. while 1:
  13. if select.select([conn], [], [], 5) == ([], [], []):
  14. pass
  15. else:
  16. conn.poll()
  17. while conn.notifies:
  18. notify = conn.notifies.pop()
  19. print('\n')
  20. print("Notificação assincrona:", notify.pid, notify.channel, notify.payload)
  21. spinner.stop()
Add Comment
Please, Sign In to add comment