In openerp Dispatch PostgreSQL notifications to the relevant polling threads to Bus.loop listen imbus on db PostgreSQL and create the listen imbus and check the condition dispatch to local threads and greenlets in channel.
Example
use this code in your own module in .py file,
def loop_create(self):
""" Dispatch postgres notifications to the relevant polling threads/greenlets """
_logger.info("Bus.loop listen imbus on db postgres")
with openerp.sql_db.db_connect('postgres').cursor() as cr:
conn = cr._cnx
cr.execute("listen imbus")
cr.commit();
while True:
if select.select([conn], [], [], TIMEOUT) == ([], [], []):
pass
else:
conn.poll()
channels = []
while conn.notifies:
channels.extend(json.loads(conn.notifies.pop().payload))
# dispatch to local threads/greenlets
events = set()
for channel in channels:
events.update(self.channels.pop(hashable(channel), []))
for event in events:
event.set()
0 Comment(s)