當前位置: 首頁>>代碼示例>>Python>>正文


Python process.Process類代碼示例

本文整理匯總了Python中circus.process.Process的典型用法代碼示例。如果您正苦於以下問題:Python Process類的具體用法?Python Process怎麽用?Python Process使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Process類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_issue310

    def test_issue310(self):
        """
        https://github.com/mozilla-services/circus/pull/310

        Allow $(circus.sockets.name) to be used in args.
        """
        conf = get_config(_CONF["issue310"])
        watcher = Watcher.load_from_config(conf["watchers"][0])
        socket = CircusSocket.load_from_config(conf["sockets"][0])
        watcher.initialize(None, {"web": socket}, None)
        process = Process(
            watcher._process_counter,
            watcher.cmd,
            args=watcher.args,
            working_dir=watcher.working_dir,
            shell=watcher.shell,
            uid=watcher.uid,
            gid=watcher.gid,
            env=watcher.env,
            rlimits=watcher.rlimits,
            spawn=False,
            executable=watcher.executable,
            use_fds=watcher.use_sockets,
            watcher=watcher,
        )

        fd = watcher._get_sockets_fds()["web"]
        formatted_args = process.format_args()

        self.assertEquals(formatted_args, ["foo", "--fd", str(fd)])
開發者ID:B-Rich,項目名稱:circus,代碼行數:30,代碼來源:test_config.py

示例2: test_rlimits

    def test_rlimits(self):
        script_file = self.get_tmpfile(RLIMIT)
        output_file = self.get_tmpfile()

        cmd = sys.executable
        args = [script_file, output_file]
        rlimits = {'nofile': 20,
                   'nproc': 20}

        process = Process('test', cmd, args=args, rlimits=rlimits)
        try:
            # wait for the process to finish
            while process.status == RUNNING:
                time.sleep(1)
        finally:
            process.stop()

        with open(output_file, 'r') as f:
            output = {}
            for line in f.readlines():
                limit, value = line.rstrip().split('=', 1)
                output[limit] = value

        def srt2ints(val):
            return [circus.py3compat.long(key) for key in val[1:-1].split(',')]

        wanted = [circus.py3compat.long(20), circus.py3compat.long(20)]

        self.assertEqual(srt2ints(output['NOFILE']), wanted)
        self.assertEqual(srt2ints(output['NPROC']), wanted)
開發者ID:cdugz,項目名稱:circus,代碼行數:30,代碼來源:test_process.py

示例3: test_rlimits

    def test_rlimits(self):
        script_file = self.get_tmpfile(RLIMIT)
        output_file = self.get_tmpfile()

        cmd = PYTHON
        args = [script_file, output_file]
        rlimits = {'nofile': 20,
                   'nproc': 20}

        process = Process('test', cmd, args=args, rlimits=rlimits)
        poll_for(output_file, 'END')
        process.stop()

        with open(output_file, 'r') as f:
            output = {}
            for line in f.readlines():
                line = line.rstrip()
                line = line.split('=', 1)
                if len(line) != 2:
                    continue
                limit, value = line
                output[limit] = value

        def srt2ints(val):
            return [circus.py3compat.long(key) for key in val[1:-1].split(',')]

        wanted = [circus.py3compat.long(20), circus.py3compat.long(20)]

        self.assertEqual(srt2ints(output['NOFILE']), wanted)
        self.assertEqual(srt2ints(output['NPROC']), wanted)
開發者ID:andrewsmedina,項目名稱:circus,代碼行數:30,代碼來源:test_process.py

示例4: test_issue310

    def test_issue310(self):
        '''
        https://github.com/mozilla-services/circus/pull/310

        Allow $(circus.sockets.name) to be used in args.
        '''
        conf = get_config(_CONF['issue310'])
        watcher = Watcher.load_from_config(conf['watchers'][0])
        socket = CircusSocket.load_from_config(conf['sockets'][0])
        try:
            watcher.initialize(None, {'web': socket}, None)
            process = Process(watcher._nextwid, watcher.cmd,
                              args=watcher.args,
                              working_dir=watcher.working_dir,
                              shell=watcher.shell, uid=watcher.uid,
                              gid=watcher.gid, env=watcher.env,
                              rlimits=watcher.rlimits, spawn=False,
                              executable=watcher.executable,
                              use_fds=watcher.use_sockets,
                              watcher=watcher)

            sockets_fds = watcher._get_sockets_fds()
            formatted_args = process.format_args(sockets_fds=sockets_fds)

            fd = sockets_fds['web']
            self.assertEqual(formatted_args,
                             ['foo', '--fd', str(fd)])
        finally:
            socket.close()
開發者ID:SEJeff,項目名稱:circus,代碼行數:29,代碼來源:test_config.py

示例5: test_rlimits

    def test_rlimits(self):
        script_file = self.get_tmpfile(RLIMIT)
        output_file = self.get_tmpfile()

        cmd = sys.executable
        args = [script_file, output_file]
        rlimits = {"nofile": 20, "nproc": 20}

        process = Process("test", cmd, args=args, rlimits=rlimits)
        poll_for(output_file, "END")
        process.stop()

        with open(output_file, "r") as f:
            output = {}
            for line in f.readlines():
                line = line.rstrip()
                line = line.split("=", 1)
                if len(line) != 2:
                    continue
                limit, value = line
                output[limit] = value

        def srt2ints(val):
            return [circus.py3compat.long(key) for key in val[1:-1].split(",")]

        wanted = [circus.py3compat.long(20), circus.py3compat.long(20)]

        self.assertEqual(srt2ints(output["NOFILE"]), wanted)
        self.assertEqual(srt2ints(output["NPROC"]), wanted)
開發者ID:jwal,項目名稱:circus,代碼行數:29,代碼來源:test_process.py

示例6: test_initgroups

 def test_initgroups(self):
     cmd = sys.executable
     args = [SLEEP % 2]
     gid = os.getgid()
     uid = os.getuid()
     p1 = Process('1', cmd, args=args, gid=gid, uid=uid)
     p1.stop()
開發者ID:andrewsmedina,項目名稱:circus,代碼行數:7,代碼來源:test_process.py

示例7: test_initgroups

 def test_initgroups(self):
     cmd = sys.executable
     args = ['import time; time.sleep(2)']
     gid = os.getgid()
     uid = os.getuid()
     p1 = Process('1', cmd, args=args, gid=gid, uid=uid)
     p1.stop()
開發者ID:IsCoolEntertainment,項目名稱:debpkg_circus,代碼行數:7,代碼來源:test_process.py

示例8: load

 def load(watcher_conf):
     watcher = Watcher.load_from_config(watcher_conf.copy())
     process = Process(watcher._nextwid, watcher.cmd,
                       args=watcher.args,
                       working_dir=watcher.working_dir,
                       shell=watcher.shell, uid=watcher.uid,
                       gid=watcher.gid, env=watcher.env,
                       rlimits=watcher.rlimits, spawn=False,
                       executable=watcher.executable,
                       use_fds=watcher.use_sockets,
                       watcher=watcher)
     return process.format_args()
開發者ID:SEJeff,項目名稱:circus,代碼行數:12,代碼來源:test_config.py

示例9: test_process_parameters

    def test_process_parameters(self):

        # all the options passed to the process should be available by the
        # command / process

        p1 = Process('1', 'make-me-a-coffee',
                '$(circus.wid) --type $(circus.env.type)',
                     shell=False, spawn=False, env={'type': 'macchiato'})

        self.assertEquals(['make-me-a-coffee', '1', '--type', 'macchiato'],
                          p1.format_args())

        p2 = Process('1', 'yeah $(CIRCUS.WID)', spawn=False)
        self.assertEquals(['yeah', '1'], p2.format_args())
開發者ID:KristianOellegaard,項目名稱:circus,代碼行數:14,代碼來源:test_process.py

示例10: test_streams

    def test_streams(self):
        script_file = self.get_tmpfile(VERBOSE)
        output_file = self.get_tmpfile()

        cmd = sys.executable
        args = [script_file, output_file]

        # 1. streams sent to /dev/null
        process = Process("test", cmd, args=args, close_child_stdout=True, close_child_stderr=True)
        try:
            poll_for(output_file, "END")

            # the pipes should be empty
            self.assertEqual(process.stdout.read(), b"")
            self.assertEqual(process.stderr.read(), b"")
        finally:
            process.stop()

        # 2. streams sent to /dev/null, no PIPEs
        output_file = self.get_tmpfile()
        args[1] = output_file

        process = Process(
            "test",
            cmd,
            args=args,
            close_child_stdout=True,
            close_child_stderr=True,
            pipe_stdout=False,
            pipe_stderr=False,
        )

        try:
            poll_for(output_file, "END")
            # the pipes should be unexistant
            self.assertTrue(process.stdout is None)
            self.assertTrue(process.stderr is None)
        finally:
            process.stop()

        # 3. streams & pipes open
        output_file = self.get_tmpfile()
        args[1] = output_file
        process = Process("test", cmd, args=args)

        try:
            poll_for(output_file, "END")

            # the pipes should be unexistant
            self.assertEqual(len(process.stdout.read()), 2890)
            self.assertEqual(len(process.stderr.read()), 2890)
        finally:
            process.stop()
開發者ID:jwal,項目名稱:circus,代碼行數:53,代碼來源:test_process.py

示例11: load

        def load(watcher_conf):
            watcher = Watcher.load_from_config(watcher_conf.copy())

            # Make sure we don't close the sockets as we will be
            # launching the Watcher with IS_WINDOWS=True
            watcher.use_sockets = True

            process = Process(watcher._nextwid, watcher.cmd,
                              args=watcher.args,
                              working_dir=watcher.working_dir,
                              shell=watcher.shell, uid=watcher.uid,
                              gid=watcher.gid, env=watcher.env,
                              rlimits=watcher.rlimits, spawn=False,
                              executable=watcher.executable,
                              use_fds=watcher.use_sockets,
                              watcher=watcher)
            return process.format_args()
開發者ID:josegonzalez,項目名稱:circus,代碼行數:17,代碼來源:test_config.py

示例12: test_streams

    def test_streams(self):
        script_file = self.get_tmpfile(VERBOSE)
        cmd = sys.executable
        args = [script_file]

        # 1. streams sent to /dev/null
        process = Process('test', cmd, args=args, close_child_stdout=True,
                          close_child_stderr=True)
        try:
            # wait for the process to finish
            while process.status == RUNNING:
                time.sleep(1)

            # the pipes should be empty
            self.assertEqual(process.stdout.read(), b'')
            self.assertEqual(process.stderr.read(), b'')
        finally:
            process.stop()

        # 2. streams sent to /dev/null, no PIPEs
        process = Process('test', cmd, args=args, close_child_stdout=True,
                          close_child_stderr=True, pipe_stdout=False,
                          pipe_stderr=False)

        try:
            # wait for the process to finish
            while process.status == RUNNING:
                time.sleep(1)

            # the pipes should be unexistant
            self.assertTrue(process.stdout is None)
            self.assertTrue(process.stderr is None)
        finally:
            process.stop()

        # 3. streams & pipes open
        process = Process('test', cmd, args=args)

        try:
            # wait for the process to finish
            while process.status == RUNNING:
                time.sleep(1)

            # the pipes should be unexistant
            self.assertEqual(len(process.stdout.read()), 2890)
            self.assertEqual(len(process.stderr.read()), 2890)
        finally:
            process.stop()
開發者ID:cdugz,項目名稱:circus,代碼行數:48,代碼來源:test_process.py

示例13: test_issue310

    def test_issue310(self):
        """
        https://github.com/mozilla-services/circus/pull/310

        Allow $(circus.sockets.name) to be used in args.
        """
        conf = get_config(_CONF["issue310"])
        watcher = Watcher.load_from_config(conf["watchers"][0])
        socket = CircusSocket.load_from_config(conf["sockets"][0])
        try:
            watcher.initialize(None, {"web": socket}, None)

            if IS_WINDOWS:
                # We can't close the sockets on Windows as we
                # are redirecting stdout
                watcher.use_sockets = True

            process = Process(
                watcher._nextwid,
                watcher.cmd,
                args=watcher.args,
                working_dir=watcher.working_dir,
                shell=watcher.shell,
                uid=watcher.uid,
                gid=watcher.gid,
                env=watcher.env,
                rlimits=watcher.rlimits,
                spawn=False,
                executable=watcher.executable,
                use_fds=watcher.use_sockets,
                watcher=watcher,
            )

            sockets_fds = watcher._get_sockets_fds()
            formatted_args = process.format_args(sockets_fds=sockets_fds)

            fd = sockets_fds["web"]
            self.assertEqual(formatted_args, ["foo", "--fd", str(fd)])
        finally:
            socket.close()
開發者ID:eikonomega,項目名稱:circus,代碼行數:40,代碼來源:test_config.py

示例14: test_base

 def test_base(self):
     cmd = "%s -c 'import time; time.sleep(2)'"
     process = Process('test', cmd % sys.executable, shell=True)
     try:
         info = process.info()
         self.assertEqual(process.pid, info['pid'])
         age = process.age()
         self.assertTrue(age > 0.)
         self.assertFalse(process.is_child(0))
     finally:
         process.stop()
開發者ID:jrgm,項目名稱:circus,代碼行數:11,代碼來源:test_process.py

示例15: test_base

 def test_base(self):
     cmd = sys.executable
     args = "-c 'import time; time.sleep(2)'"
     process = Process("test", cmd, args=args, shell=False)
     try:
         info = process.info()
         self.assertEqual(process.pid, info["pid"])
         age = process.age()
         self.assertTrue(age > 0.0)
         self.assertFalse(process.is_child(0))
     finally:
         process.stop()
開發者ID:jwal,項目名稱:circus,代碼行數:12,代碼來源:test_process.py


注:本文中的circus.process.Process類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。