当前位置: 首页>>代码示例>>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;未经允许,请勿转载。