コード例 #1
0
ファイル: bus.py プロジェクト: Lawouach/conductor
 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)
コード例 #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)
コード例 #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)
コード例 #4
0
ファイル: process.py プロジェクト: Lawouach/conductor
    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)
コード例 #5
0
ファイル: process.py プロジェクト: Lawouach/conductor
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()
コード例 #6
0
    def start(self):
        Bus.start(self)

        handler = (self._clean_exit, (), {})
        if handler in atexit._exithandlers:
            atexit._exithandlers.remove(handler)
コード例 #7
0
 def start(self):
     self.log("Syncing on main process")
     self.condition.acquire()
     self.condition.wait()
     self.condition.release()
     Bus.start(self)
コード例 #8
0
 def __init__(self, cond):
     Bus.__init__(self)
     self.condition = cond
コード例 #9
0
 def __init__(self, sync_delay=1):
     Bus.__init__(self)
     self.sync_delay = sync_delay
     self.condition = Condition()
コード例 #10
0
ファイル: bus.py プロジェクト: Lawouach/conductor
    def start(self):
        Bus.start(self)

        handler = (self._clean_exit, (), {})
        if handler in atexit._exithandlers:
            atexit._exithandlers.remove(handler)
コード例 #11
0
ファイル: bus.py プロジェクト: Lawouach/conductor
 def start(self):
     self.log("Syncing on main process")
     self.condition.acquire()
     self.condition.wait()
     self.condition.release()
     Bus.start(self)
コード例 #12
0
ファイル: bus.py プロジェクト: Lawouach/conductor
 def __init__(self, cond):
     Bus.__init__(self)
     self.condition = cond
コード例 #13
0
ファイル: bus.py プロジェクト: Lawouach/conductor
 def __init__(self, sync_delay=1):
     Bus.__init__(self)
     self.sync_delay = sync_delay
     self.condition = Condition()
コード例 #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()