Esempio n. 1
0
    def __init__(self, host=CELERY_RDB_HOST, port=CELERY_RDB_PORT,
            port_search_limit=100, port_skew=+0):
        self.active = True

        try:
            from celery.utils.mp import current_process
            if current_process:
                _, port_skew = current_process().name.split('-')
        except (ImportError, ValueError):
            pass
        port_skew = int(port_skew)

        self._prev_handles = sys.stdin, sys.stdout
        this_port = None
        for i in xrange(port_search_limit):
            self._sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            this_port = port + port_skew + i
            try:
                self._sock.bind((host, this_port))
            except socket.error, exc:
                if exc.errno in [errno.EADDRINUSE, errno.EINVAL]:
                    continue
                raise
            else:
                break
Esempio n. 2
0
 def test_worker_term_handler_only_stop_MainProcess(self):
     if current_process is None:
         raise SkipTest("only relevant for multiprocessing")
     process = current_process()
     name, process.name = process.name, "OtherProcess"
     try:
         worker = self._Worker()
         handlers = self.psig(cd.install_worker_term_handler, worker)
         with self.assertRaises(SystemExit):
             handlers["SIGTERM"]("SIGTERM", object())
         self.assertFalse(worker.stopped)
     finally:
         process.name = name
Esempio n. 3
0
    def set_mp_process_title(progname, info=None, hostname=None,  # noqa
            rate_limit=False):
        """Set the ps name using the multiprocessing process name.

        Only works if :mod:`setproctitle` is installed.

        """
        if not rate_limit or _setps_bucket.can_consume(1):
            if hostname:
                progname = "%s@%s" % (progname, hostname.split(".")[0])
            if current_process is not None:
                return set_process_title(
                    "%s:%s" % (progname, current_process().name), info=info)
            else:
                return set_process_title(progname, info=info)