Ejemplo n.º 1
0
 def run_subscribe(self):
     e = Observer()
     getcurrent().in_another_greenlet = self.in_another_greenlet
     getcurrent().in_another_greenlet2 = self.in_another_greenlet2
     b = e.subscribe('kill',getcurrent().in_another_greenlet)
     c = e.subscribe('kill',getcurrent().in_another_greenlet2)
     gevent.sleep(1)
     b.unsubscribe()
     c.unsubscribe()
Ejemplo n.º 2
0
 def run_cancel(self):
     try:
         e = Observer()
         ev = e.wait('kill')
         ev.cancel()
         gevent.sleep(1)
     except FiredEvent:
         return False
     else:
         return True
Ejemplo n.º 3
0
 def run_wait(self):
     e = Observer()
     ev = e.wait('kill')
     try:
         gevent.sleep(1)
     except FiredEvent:
         return True
     else:
         return False
     finally:
         ev.cancel()
Ejemplo n.º 4
0
Archivo: app.py Proyecto: creotiv/gflib
 def _reload_config(self):
     o = Observer()
     o.fire('reload_config')
Ejemplo n.º 5
0
Archivo: app.py Proyecto: creotiv/gflib
 def _stop_child(self, sig=None, frame=None):
     """It's executed when server shutdown. Used for correct shutdown.
     """     
     e = Observer()
     e.fire('shutdown')
Ejemplo n.º 6
0
 def fire_event(self):
     e2 = Observer()
     e2.fire('kill')
Ejemplo n.º 7
0
 def __init__(self,pnum,sockets=None):
     self.proc_num   = pnum
     self.sockets    = sockets
     self.events     = Observer()
     self.conf       = Config.getInstance()
Ejemplo n.º 8
0
class DaemonChild(object):
    """Main runner. Initialize all modules and start process loop"""
    def __init__(self,pnum,sockets=None):
        self.proc_num   = pnum
        self.sockets    = sockets
        self.events     = Observer()
        self.conf       = Config.getInstance()
        
    def run(self):
        logging.debug(self.proc_num)
        self._main_loop()
        """if self.proc_num == 0:    
            self._main_loop()
        elif self.proc_num == 1:
            self._broker_loop()
        elif self.proc_num > 1:
            self._worker_loop()"""
        
        
    @classmethod
    def reload_config(cls):
        pass
       
    def _shutdown(self):
        logging.debug('Shuting down the daemon child.')
        logging.shutdown()
        # Use only for child processes after fork
        os._exit(0)
        
    def _broker_loop(self):
        self.events.subscribe('shutdown',self._shutdown)
        try:
            context = zmq.Context()
            frontend = context.socket(zmq.XREP)
            backend = context.socket(zmq.XREQ)
            frontend.bind("tcp://*:5559")
            backend.bind("tcp://*:5560")

            # Initialize poll set
            poller = zmq.Poller()
            poller.register(frontend, zmq.POLLIN)
            poller.register(backend, zmq.POLLIN)

            # Switch messages between sockets
            while True:
                socks = dict(poller.poll())

                if socks.get(frontend) == zmq.POLLIN:
                    message = frontend.recv()
                    more = frontend.getsockopt(zmq.RCVMORE)
                    if more:
                        backend.send(message, zmq.SNDMORE)
                    else:
                        backend.send(message)

                if socks.get(backend) == zmq.POLLIN:
                    message = backend.recv()
                    more = backend.getsockopt(zmq.RCVMORE)
                    if more:
                        frontend.send(message, zmq.SNDMORE)
                    else:
                        frontend.send(message)

        except Exception,e:
            logging.exception(e)
            self._shutdown()