notifyexample.py
changeset 36 e67101c22e83
child 93 b72591087495
equal deleted inserted replaced
35:e7f79c4a27ce 36:e67101c22e83
       
     1 #!/usr/bin/env python3.2
       
     2 #
       
     3 # Call "NOTIFY notifyexample" on target DB to wake up this program.
       
     4 #
       
     5 
       
     6 from pgtoolkit import toolbase, pgmanager
       
     7 
       
     8 
       
     9 class NotifyExample(toolbase.SimpleTool):
       
    10     def __init__(self):
       
    11         toolbase.SimpleTool.__init__(self, name='notifyexample', desc='Sample program for listen/notify.')
       
    12         self.init()
       
    13 
       
    14     def main(self):
       
    15         # create another connection for notifies, copy parameters from connection 'target'
       
    16         self.pgm.create_conn_listen('target_listen', channel='notifyexample', copy_dsn='target')
       
    17         while True:
       
    18             ev = self.pgm.wait_for_notify('target_listen', timeout=None)
       
    19             if ev:
       
    20                 print(ev)
       
    21 
       
    22 
       
    23 tool = NotifyExample()
       
    24 tool.main()
       
    25