示例#1
0
    def test_simple_usage(self):
        commands = [
            'ls',
        ]

        lil = Pool(workers=1)
        lil.run(commands)

        lil = Pool(workers=2)
        lil.run(commands)

        # Should raise an exception.
        self.assertRaises(NotEnoughWorkers, Pool, workers=0)
示例#2
0
    def test_long_wait_time(self):
        lil = Pool(workers=1)
        start = time.time()
        lil.run(['ls'])
        end = time.time()
        self.assertTrue(end - start < 1.0)

        # Now with a longer wait.
        lil = Pool(workers=1, wait_time=1.25)
        start = time.time()
        lil.run(['ls'])
        end = time.time()
        self.assertTrue(end - start > 1.0)
示例#3
0
    def test_callback(self):
        lil = Pool(workers=1)
        commands = [
            'sleep 1',
            'sleep 1',
            'i_am_a_super-jacked-command_you_ought-not_to-have_on-your-1_system',
            'sleep 1',
        ]

        # Track exit codes.
        codes = []

        def track(proc):
            codes.append(proc.returncode)

        lil.run(commands, callback=track)

        self.assertEqual(lil.callback, track)
        self.assertEqual(codes, [0, 0, 127, 0])