'Dispatch postgres notifications to the relevant polling threads/greenlets'

def loop(self):

    _logger.info('Bus.loop    listen    imbus    on    db    postgres')
    with odoo.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))
                events = set()
                for channel in channels:
                    events.update(self.channels.pop(hashable(channel), []))
                for event in events:
                    event.set()
