notifyexample.py
changeset 36 e67101c22e83
child 93 b72591087495
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/notifyexample.py	Wed May 23 11:11:16 2012 +0200
@@ -0,0 +1,25 @@
+#!/usr/bin/env python3.2
+#
+# Call "NOTIFY notifyexample" on target DB to wake up this program.
+#
+
+from pgtoolkit import toolbase, pgmanager
+
+
+class NotifyExample(toolbase.SimpleTool):
+    def __init__(self):
+        toolbase.SimpleTool.__init__(self, name='notifyexample', desc='Sample program for listen/notify.')
+        self.init()
+
+    def main(self):
+        # create another connection for notifies, copy parameters from connection 'target'
+        self.pgm.create_conn_listen('target_listen', channel='notifyexample', copy_dsn='target')
+        while True:
+            ev = self.pgm.wait_for_notify('target_listen', timeout=None)
+            if ev:
+                print(ev)
+
+
+tool = NotifyExample()
+tool.main()
+