Re: NOTIFY/LISTEN in Postgresql
От | Sim Zacks |
---|---|
Тема | Re: NOTIFY/LISTEN in Postgresql |
Дата | |
Msg-id | 507C18FD.6010309@compulab.co.il обсуждение исходный текст |
Ответ на | NOTIFY/LISTEN in Postgresql ("P. Broennimann" <peter.broennimann@gmail.com>) |
Список | pgsql-general |
<div class="moz-cite-prefix">On 10/15/2012 02:54 PM, P. Broennimann wrote:<br /></div><blockquote cite="mid:CACm4aU-eFNaDiYw9uH1n9VPgHN5SqseJ3HqsbgXd7-Cw++NF-g@mail.gmail.com"type="cite"><font face="courier new, monospace">Hithere</font><div><font face="courier new, monospace"><br /></font></div><div><font face="courier new, monospace">1)Can a Pg/SQL function "listen" for a notification sent from an external instance?</font></div><div><span style="font-family:'couriernew',monospace">I would like my stored function to pause/wait and continue its execution oncean external event (NOTIFY event) occurs.</span></div></blockquote><blockquote cite="mid:CACm4aU-eFNaDiYw9uH1n9VPgHN5SqseJ3HqsbgXd7-Cw++NF-g@mail.gmail.com"type="cite"><br /><div><font face="courier new,monospace">2) In </font><span style="font-family:'courier new',monospace">Pg/SQL I can implement a loop (until somethinghappens) to pause/wait. This costs CPU time -> Is there another solution? Actually I would need something likea trigger to give my stored function the signal to continue.</span></div></blockquote><br /> Yes. I played around withthis a while ago, and thought the possibility was beyond cool.<br /> However, after playing around with it and gettingsome constructive criticism, I decided that it would be better to keep the different application layers completelyseparated, so that the database layer would not be talking directly to the GUI.<br /><br /> Here is an examplefunction that I sent to the list a year+ ago.<br /><a href="http://archives.postgresql.org/pgsql-general/2011-06/msg00322.php">http://archives.postgresql.org/pgsql-general/2011-06/msg00322.php</a><br /><br/> On the client end, I had something like this:<br /> class ListenThread(threading.Thread): <br /> def __init__(self,frame):<br/> threading.Thread.__init__(self)<br /> self.frame=frame<br /> <br /> def run(self):<br /> HOST, PORT = "192.168.1.207", 8080<br /> <br /> # Create the server,binding to localhost on port 8080<br /> server = SocketServer.TCPServer((HOST, PORT), MyTCPHandler)<br/> server.frame=self.frame<br /> # Activate the server; this will keep running untilyou<br /> # interrupt the program with Ctrl-C<br /> server.serve_forever() <br /><br />
В списке pgsql-general по дате отправления: