コード例 #1
0
ファイル: monitor.py プロジェクト: jasonrubenstein/feather
    def _worker_postfork(self, tmpfd):
        self.log.info("initializing worker")

        if self.worker_uid is not None:
            self.log.info("setting worker uid")
            os.setuid(self.worker_uid)

        if self.worker_gid is not None:
            self.log.info("setting worker gid")
            os.setgid(self.worker_gid)

        if self.readiness_notifier is not None:
            scheduler.end(self.readiness_notifier)

        scheduler.reset_poller()

        if self.original:
            scheduler.schedule(self.worker_inform_ready)

        self.clear_master_signals()
        self.apply_worker_signals()

        for t in self.workers.values():
            t.cancel()
        self.workers = None

        self.log.info("starting health timer")
        self.worker_health_timer(tmpfd)
        self.zombie_checker.cancel()

        self.worker_postfork()
コード例 #2
0
ファイル: utils.py プロジェクト: philippp/greenhouse
 def send(self, item):
     if self._waiters and not self._dataqueue:
         self._dataqueue.append(item)
         if self.preference is -1:
             scheduler.schedule(greenlet.getcurrent())
             self._waiters.popleft().switch()
         else:
             scheduler.schedule(self._waiters.popleft())
     else:
         self._dataqueue.append(item)
         self._waiters.append(greenlet.getcurrent())
         state.mainloop.switch()
コード例 #3
0
ファイル: util.py プロジェクト: PlumpMath/greenhouse
    def put(self, item, block=True, timeout=None):
        """put an item into the queue

        .. note::

            if the queue was created with a `maxsize` and it is currently
            :meth:`full`, this method will block the calling coroutine until
            another coroutine :meth:`get`\ s an item.

        :param item: the object to put into the queue, can be any type
        :param block:
            whether to block if the queue is already :meth:`full` (default
            ``True``)
        :type block: bool
        :param timeout:
            the maximum time in seconds to block waiting. with the default of
            ``None``, it can wait indefinitely. this is unused if `block` is
            ``False``.
        :type timeout: int, float or None

        :raises:
            :class:`Full` if the queue is :meth:`full` and `block` is
            ``False``, or if `timeout` expires.
        """
        if self.full():
            if not block:
                raise Full()

            current = compat.getcurrent()

            waketime = None if timeout is None else time.time() + timeout
            if timeout is not None:
                scheduler.schedule_at(waketime, current)
            self._waiters.append((current, waketime))

            scheduler.state.mainloop.switch()

            if timeout is not None:
                if not scheduler._remove_timer(waketime, current):
                    self._waiters.remove((current, waketime))
                    raise Full()

        if self._waiters and not self.full():
            scheduler.schedule(self._waiters.popleft()[0])

        if not self._open_tasks:
            self._jobs_done.clear()
        self._open_tasks += 1

        self._put(item)
コード例 #4
0
ファイル: util.py プロジェクト: dsully/greenhouse
    def put(self, item, blocking=True, timeout=None):
        """put an item into the queue

        .. note::

            if the queue was created with a `maxsize` and it is currently
            :meth:`full`, this method will block the calling coroutine until
            another coroutine :meth:`get`\ s an item.

        :param item: the object to put into the queue, can be any type
        :param blocking:
            whether to block if the queue is already :meth:`full` (default
            ``True``)
        :type blocking: bool
        :param timeout:
            the maximum time in seconds to block waiting. with the default of
            ``None``, it can wait indefinitely. this is unused if `blocking` is
            ``False``.
        :type timeout: int, float or None

        :raises:
            :class:`Full` if the queue is :meth:`full` and `blocking` is
            ``False``, or if `timeout` expires.
        """
        if self.full():
            if not blocking:
                raise Full()

            current = compat.getcurrent()

            waketime = None if timeout is None else time.time() + timeout
            if timeout is not None:
                scheduler.schedule_at(waketime, current)
            self._waiters.append((current, waketime))

            scheduler.state.mainloop.switch()

            if timeout is not None:
                if not scheduler._remove_timer(waketime, current):
                    self._waiters.remove((current, waketime))
                    raise Full()

        if self._waiters and not self.full():
            scheduler.schedule(self._waiters.popleft()[0])

        if not self._open_tasks:
            self._jobs_done.clear()
        self._open_tasks += 1

        self._put(item)
コード例 #5
0
ファイル: utils.py プロジェクト: philippp/greenhouse
 def receive(self):
     if self._closing and not self._dataqueue:
         raise StopIteration()
     if self._dataqueue:
         item = self._dataqueue.popleft()
         sender = self._waiters.popleft()
         if self.preference is 1:
             scheduler.schedule(greenlet.getcurrent())
             sender.switch()
         else:
             scheduler.schedule(sender)
         return item
     else:
         self._waiters.append(greenlet.getcurrent())
         state.mainloop.switch()
         return self._dataqueue.pop()
コード例 #6
0
ファイル: util.py プロジェクト: PlumpMath/greenhouse
    def get(self, block=True, timeout=None):
        """get an item out of the queue

        .. note::

            if `block` is ``True`` (the default) and the queue is
            :meth`empty`, this method will block the current coroutine until
            something has been :meth:`put`.

        :param block:
            whether to block if there is no data yet available (default
            ``True``)
        :type block: bool
        :param timeout:
            the maximum time in seconds to block waiting for data. with the
            default of ``None``, can wait indefinitely. this is unused if
            `block` is ``False``.
        :type timeout: int, float or None

        :raises:
            :class:`Empty` if there is no data in the queue and block is
            ``False``, or `timeout` expires

        :returns: something that was previously :meth:`put` in the queue
        """
        if not self._data:
            if not block:
                raise Empty()

            current = compat.getcurrent()

            waketime = None if timeout is None else time.time() + timeout
            if timeout is not None:
                scheduler.schedule_at(waketime, current)
            self._waiters.append((current, waketime))

            scheduler.state.mainloop.switch()

            if timeout is not None:
                if not scheduler._remove_timer(waketime, current):
                    self._waiters.remove((current, waketime))
                    raise Empty()

        if self.full() and self._waiters:
            scheduler.schedule(self._waiters.popleft()[0])

        return self._get()
コード例 #7
0
ファイル: util.py プロジェクト: dsully/greenhouse
    def get(self, blocking=True, timeout=None):
        """get an item out of the queue

        .. note::

            if `blocking` is ``True`` (the default) and the queue is
            :meth`empty`, this method will block the current coroutine until
            something has been :meth:`put`.

        :param blocking:
            whether to block if there is no data yet available (default
            ``True``)
        :type blocking: bool
        :param timeout:
            the maximum time in seconds to block waiting for data. with the
            default of ``None``, can wait indefinitely. this is unused if
            `blocking` is ``False``.
        :type timeout: int, float or None

        :raises:
            :class:`Empty` if there is no data in the queue and blocking is
            ``False``, or `timeout` expires

        :returns: something that was previously :meth:`put` in the queue
        """
        if not self._data:
            if not blocking:
                raise Empty()

            current = compat.getcurrent()

            waketime = None if timeout is None else time.time() + timeout
            if timeout is not None:
                scheduler.schedule_at(waketime, current)
            self._waiters.append((current, waketime))

            scheduler.state.mainloop.switch()

            if timeout is not None:
                if not scheduler._remove_timer(waketime, current):
                    self._waiters.remove((current, waketime))
                    raise Empty()

        if self.full() and self._waiters:
            scheduler.schedule(self._waiters.popleft()[0])

        return self._get()
コード例 #8
0
ファイル: util.py プロジェクト: felinx/greenhouse
    def start(self):
        """schedule to start the greenlet that runs this thread's function

        :raises: `RuntimeError` if the thread has already been started
        """
        if self._started:
            raise RuntimeError("thread already started")

        def run():
            try:
                self.run(*self._args, **self._kwargs)
            finally:
                self._deactivate()

        self._glet = scheduler.greenlet(run)
        scheduler.schedule(self._glet)
        self._activate()
コード例 #9
0
ファイル: util.py プロジェクト: dsully/greenhouse
    def start(self):
        """schedule to start the greenlet that runs this thread's function

        :raises: `RuntimeError` if the thread has already been started
        """
        if self._started:
            raise RuntimeError("thread already started")
        def run():
            try:
                self.run(*self._args, **self._kwargs)
            except SystemExit:
                # only shut down the thread, not the whole process
                pass
            finally:
                self._deactivate()
        self._glet = scheduler.greenlet(run)
        scheduler.schedule(self._glet)
        self._activate()
コード例 #10
0
ファイル: util.py プロジェクト: PlumpMath/greenhouse
    def start(self):
        """schedule to start the greenlet that runs this thread's function

        :raises: `RuntimeError` if the thread has already been started
        """
        if self._started:
            raise RuntimeError("thread already started")

        def run():
            try:
                self.run(*self._args, **self._kwargs)
            except SystemExit:
                # only shut down the thread, not the whole process
                pass
            finally:
                self._deactivate()

        self._glet = scheduler.greenlet(run)
        self._ident = id(self._glet)
        scheduler.schedule(self._glet)
        self._activate()
コード例 #11
0
    def _worker_postfork(self, wid, pid, tmpfd):
        self.log.info("initializing worker")

        with io.File(self.control_path(self.WORKER_PIDFILE % wid), 'w') as fp:
            fp.write(str(os.getpid()))

        if self.worker_gid is not None:
            self.log.info("setting worker gid")
            os.setgid(self.worker_gid)

        if self.worker_uid is not None:
            self.log.info("setting worker uid")
            os.setuid(self.worker_uid)

        if self.readiness_notifier is not None:
            scheduler.end(self.readiness_notifier)

        scheduler.reset_poller()

        if self.original:
            scheduler.schedule(self.worker_inform_ready)

        self.clear_master_signals()
        self.apply_worker_signals()

        for t in self.health_checks.values():
            scheduler.end(t)
        self.workers = None
        self.rev_workers = None
        self.health_checks = None

        self.log.info("starting health timer")
        self.worker_health_timer(tmpfd)
        self.zombie_checker.cancel()

        self.worker_postfork(wid, pid)
コード例 #12
0
 def _post_worker_fork(self):
     self.original = False
     self.readiness_notifier = scheduler.greenlet(self.notify_readiness)
     scheduler.schedule(self.readiness_notifier)
コード例 #13
0
ファイル: pool.py プロジェクト: PlumpMath/greenhouse
 def start(self):
     "start the pool's workers"
     for i in xrange(self.size):
         scheduler.schedule(self._runner)
     self._closing = False
コード例 #14
0
ファイル: pool.py プロジェクト: dsully/greenhouse
 def start(self):
     "start the pool's workers"
     for i in xrange(self.size):
         scheduler.schedule(self._runner)
     self._closing = False
コード例 #15
0
 def start_server(self, port, namespace=None):
     scheduler.schedule(backdoor.run_backdoor,
                        args=(("127.0.0.1", port), namespace))
     scheduler.pause()
コード例 #16
0
ファイル: signal.py プロジェクト: PlumpMath/greenhouse
def generic_handler(delegate, *args, **kwargs):
    scheduler.schedule(delegate, args=args, kwargs=kwargs)
コード例 #17
0
ファイル: signal.py プロジェクト: aglyzov/greenhouse
def generic_handler(delegate, *args, **kwargs):
    scheduler.schedule(delegate, args=args, kwargs=kwargs)
コード例 #18
0
ファイル: test_backdoor.py プロジェクト: aglyzov/greenhouse
 def start_server(self, port, namespace=None):
     scheduler.schedule(
             backdoor.run_backdoor, args=(("127.0.0.1", port), namespace))
     scheduler.pause()
コード例 #19
0
 def health_monitor(self, pid, tmpfd, tmpfname):
     checker = scheduler.greenlet(self.health_monitor_checker,
             args=(pid, tmpfd, tmpfname))
     scheduler.schedule(checker)
     self.health_checks[pid] = checker
コード例 #20
0
ファイル: pool.py プロジェクト: philippp/greenhouse
 def start(self):
     for i in xrange(self.size):
         schedule(self._runner)