Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to handle a longpolling request in openerp

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 915
    Comment on it

    In openerp to handle a long-polling request, we need to bypass private attribute access because we do not know before starting that the thread and handles a long-polling request and rename the thread to avoid tests waiting for a long-polling.
    Example
    Use this code in your own module in .py file,

    def create_poll(self, dbname, channels, last, timeout=TIMEOUT):
            # Dont hang ctrl-c for a poll request, we need to bypass private
            # attribute access because we dont know before starting the thread that
            # it will handle a longpolling request
            if not openerp.evented:
                current = threading.current_thread()
                current._Thread__daemonic = True
                # rename the thread to avoid tests waiting for a longpolling
                current.setName("openerp.longpolling.request.%s" % current.ident)
    
            registry = openerp.registry(dbname)
    
            # immediatly returns if past notifications exist
            with registry.cursor() as cr:
                notifications = registry['bus.bus'].poll(cr, openerp.SUPERUSER_ID, channels, last)
            # or wait for future ones
            if not notifications:
                event = self.Event()
                for channel in channels:
                    self.channels.setdefault(hashable(channel), []).append(event)
                try:
                    event.wait(timeout=timeout)
                    with registry.cursor() as cr:
                        notifications = registry['bus.bus'].poll(cr, openerp.SUPERUSER_ID, channels, last)
                except Exception:
                    # timeout
                    pass
            return notifications
    

 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: