Esempio n. 1
0
 def test_initgroups(self):
     cmd = sys.executable
     args = [SLEEP % 2]
     gid = os.getgid()
     uid = os.getuid()
     p1 = Process('test', '1', cmd, args=args, gid=gid, uid=uid)
     p1.stop()
Esempio n. 2
0
    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)
Esempio n. 3
0
    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)
Esempio n. 4
0
    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)
 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()
Esempio n. 6
0
 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()
Esempio n. 7
0
    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)
Esempio n. 8
0
    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)
Esempio n. 9
0
 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()
Esempio n. 10
0
    def test_comparison(self):
        cmd = sys.executable
        args = ['import time; time.sleep(2)', ]
        p1 = Process('1', cmd, args=args)
        p2 = Process('2', cmd, args=args)

        self.assertTrue(p1 < p2)
        self.assertFalse(p1 == p2)
        self.assertTrue(p1 == p1)

        p1.stop()
        p2.stop()
Esempio n. 11
0
 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()
Esempio n. 12
0
 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.)
         self.assertFalse(process.is_child(0))
     finally:
         process.stop()
Esempio n. 13
0
    def test_comparison(self):
        cmd = sys.executable
        args = ['import time; time.sleep(2)', ]
        p1 = Process('1', cmd, args=args)
        p2 = Process('2', cmd, args=args)

        self.assertTrue(p1 < p2)
        self.assertFalse(p1 == p2)
        self.assertTrue(p1 == p1)

        p1.stop()
        p2.stop()
Esempio n. 14
0
    def test_comparison(self):
        cmd = PYTHON
        args = ['import time; time.sleep(2)', ]
        p1 = Process('1', cmd, args=args, use_fds=USE_FDS)
        # Make sure the two processes are launched with a measurable
        # difference. (precsion error on Windows)
        time.sleep(0.01)
        p2 = Process('2', cmd, args=args, use_fds=USE_FDS)

        self.assertTrue(p1 < p2)
        self.assertFalse(p1 == p2)
        self.assertTrue(p1 == p1)

        p1.stop()
        p2.stop()
Esempio n. 15
0
    def test_comparison(self):
        cmd = PYTHON
        args = ['import time; time.sleep(2)', ]
        p1 = Process('test', 1, cmd, args=args, use_fds=USE_FDS)
        # Make sure the two processes are launched with a measurable
        # difference. (precsion error on Windows)
        time.sleep(0.01)
        p2 = Process('test', 2, cmd, args=args, use_fds=USE_FDS)

        self.assertTrue(p1 < p2)
        self.assertFalse(p1 == p2)
        self.assertTrue(p1 == p1)

        p1.stop()
        p2.stop()
Esempio n. 16
0
 def test_base(self):
     cmd = PYTHON
     args = "-c 'import time; time.sleep(10)'"
     process = Process('test', cmd, args=args, shell=False,
                       use_fds=USE_FDS)
     try:
         info = process.info()
         self.assertEqual(process.pid, info['pid'])
         # Make sure the process lived a measurable amount of time
         # (precision error on Windows)
         time.sleep(0.01)
         age = process.age()
         self.assertTrue(age > 0.)
         self.assertFalse(process.is_child(0))
     finally:
         process.stop()
Esempio n. 17
0
 def test_base(self):
     cmd = PYTHON
     args = "-c 'import time; time.sleep(10)'"
     process = Process('test', 1, cmd, args=args, shell=False,
                       use_fds=USE_FDS)
     try:
         info = process.info()
         self.assertEqual(process.pid, info['pid'])
         # Make sure the process lived a measurable amount of time
         # (precision error on Windows)
         time.sleep(0.01)
         age = process.age()
         self.assertTrue(age > 0.)
         self.assertFalse(process.is_child(0))
     finally:
         process.stop()
Esempio n. 18
0
    def test_streams(self):
        script_file = self.get_tmpfile(VERBOSE)
        output_file = self.get_tmpfile()

        cmd = PYTHON
        args = [script_file, output_file]

        # 1. streams sent to /dev/null
        process = Process('test',
                          1,
                          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',
                          1,
                          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', '1', 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()
Esempio n. 19
0
    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()
Esempio n. 20
0
    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()
Esempio n. 21
0
    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()