Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to Dispatch postgres notifications to the relevant polling threads and greenlets in openerp

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 674
    Comment on it

    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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: