Beispiel #1
0
 def start(self):
     import time
     time.sleep(self.sync_delay)
     self.log("Releasing children")
     self.condition.acquire()
     self.condition.notify_all()
     self.condition.release()
     Bus.start(self)
Beispiel #2
0
 def start(self):
     import time
     time.sleep(self.sync_delay)
     self.log("Releasing children")
     self.condition.acquire()
     self.condition.notify_all()
     self.condition.release()
     Bus.start(self)
Beispiel #3
0
    def __init__(self):
        _Process.__init__(self)
        self.logger = None
        self.daemon = False
        self.interval = 0.1

        from cherrypy.process.wspbus import Bus
        self.bus = Bus()
        self.bus.subscribe('log', self.log)
Beispiel #4
0
    def __init__(self):
        _Process.__init__(self)
        self.logger = None
        self.daemon = False
        self.interval = 0.1

        from cherrypy.process.wspbus import Bus
        self.bus = Bus()
        self.bus.subscribe('log', self.log)
Beispiel #5
0
class Process(_Process):
    """
    Represents a process that can run tasks.
    """
    def __init__(self):
        _Process.__init__(self)
        self.logger = None
        self.daemon = False
        self.interval = 0.1

        from cherrypy.process.wspbus import Bus
        self.bus = Bus()
        self.bus.subscribe('log', self.log)

    def notatexit(self):
        """
        Prevents the process's bus to trap atexit.
        """
        import atexit
        handler = (self.bus._clean_exit, (), {})
        if handler in atexit._exithandlers:
            atexit._exithandlers.remove(handler)

    def register_task(self, task):
        """
        Subscribes `task` with `self.bus`.
        """
        self.log('Registering task: %s' % task.__class__)
        task.proc = self
        task.bus = self.bus
        task.subscribe()

    def unregister_task(self, task):
        """
        Unsubscribes `task` from the bus so that it isn't run
        whenever the bus starts or stops.
        """
        self.log('Unregistering task: %s' % task.__class__)
        task.proc = None
        task.unsubscribe()
        task.bus = None

    def run(self):
        """
        Start the bus and blocks on the bus.
        """
        self.log("Process PID: %d" % (self.pid or os.getpid(),))

        from cherrypy.process import plugins
        sig = plugins.SignalHandler(self.bus)
        if sys.platform[:4] == 'java':
            # See http://bugs.jython.org/issue1313
            sig.handlers['SIGINT'] = self._jython_handle_SIGINT
        sig.subscribe()

        if self.daemon:
            plugins.Daemonizer(self.bus).subscribe()

        self.bus.start()
        self.bus.block(interval=self.interval)

    def log(self, msg, level=logging.INFO):
        if self.logger:
            self.logger.log(level, msg)

    def _jython_handle_SIGINT(self, signum=None, frame=None):
        # See http://bugs.jython.org/issue1313
        self.bus.log('Keyboard Interrupt: shutting down bus')
        self.bus.exit()
Beispiel #6
0
    def start(self):
        Bus.start(self)

        handler = (self._clean_exit, (), {})
        if handler in atexit._exithandlers:
            atexit._exithandlers.remove(handler)
Beispiel #7
0
 def start(self):
     self.log("Syncing on main process")
     self.condition.acquire()
     self.condition.wait()
     self.condition.release()
     Bus.start(self)
Beispiel #8
0
 def __init__(self, cond):
     Bus.__init__(self)
     self.condition = cond
Beispiel #9
0
 def __init__(self, sync_delay=1):
     Bus.__init__(self)
     self.sync_delay = sync_delay
     self.condition = Condition()
Beispiel #10
0
    def start(self):
        Bus.start(self)

        handler = (self._clean_exit, (), {})
        if handler in atexit._exithandlers:
            atexit._exithandlers.remove(handler)
Beispiel #11
0
 def start(self):
     self.log("Syncing on main process")
     self.condition.acquire()
     self.condition.wait()
     self.condition.release()
     Bus.start(self)
Beispiel #12
0
 def __init__(self, cond):
     Bus.__init__(self)
     self.condition = cond
Beispiel #13
0
 def __init__(self, sync_delay=1):
     Bus.__init__(self)
     self.sync_delay = sync_delay
     self.condition = Condition()
Beispiel #14
0
class Process(_Process):
    """
    Represents a process that can run tasks.
    """
    def __init__(self):
        _Process.__init__(self)
        self.logger = None
        self.daemon = False
        self.interval = 0.1

        from cherrypy.process.wspbus import Bus
        self.bus = Bus()
        self.bus.subscribe('log', self.log)

    def notatexit(self):
        """
        Prevents the process's bus to trap atexit.
        """
        import atexit
        handler = (self.bus._clean_exit, (), {})
        if handler in atexit._exithandlers:
            atexit._exithandlers.remove(handler)

    def register_task(self, task):
        """
        Subscribes `task` with `self.bus`.
        """
        self.log('Registering task: %s' % task.__class__)
        task.proc = self
        task.bus = self.bus
        task.subscribe()

    def unregister_task(self, task):
        """
        Unsubscribes `task` from the bus so that it isn't run
        whenever the bus starts or stops.
        """
        self.log('Unregistering task: %s' % task.__class__)
        task.proc = None
        task.unsubscribe()
        task.bus = None

    def run(self):
        """
        Start the bus and blocks on the bus.
        """
        self.log("Process PID: %d" % (self.pid or os.getpid(), ))

        from cherrypy.process import plugins
        sig = plugins.SignalHandler(self.bus)
        if sys.platform[:4] == 'java':
            # See http://bugs.jython.org/issue1313
            sig.handlers['SIGINT'] = self._jython_handle_SIGINT
        sig.subscribe()

        if self.daemon:
            plugins.Daemonizer(self.bus).subscribe()

        self.bus.start()
        self.bus.block(interval=self.interval)

    def log(self, msg, level=logging.INFO):
        if self.logger:
            self.logger.log(level, msg)

    def _jython_handle_SIGINT(self, signum=None, frame=None):
        # See http://bugs.jython.org/issue1313
        self.bus.log('Keyboard Interrupt: shutting down bus')
        self.bus.exit()