コード例 #1
0
ファイル: test_pool.py プロジェクト: zw0610/fiber
    def test_pool_close(self):
        pool = Pool(2)
        res = pool.map(f, [1, 2, 3])
        assert res == [1, 4, 9]
        pool.close()

        with pytest.raises(ValueError):
            pool.map(f, [1, 2, 3])

        pool.join()
コード例 #2
0
ファイル: test_pool.py プロジェクト: zw0610/fiber
    def test_pi_estimation(self):
        pool = Pool(processes=4)
        NUM_SAMPLES = int(1e6)
        pi = 4.0 * sum(pool.map(is_inside, range(0, NUM_SAMPLES))) / NUM_SAMPLES
        assert 3 < pi and pi < 4
        print("Pi is roughly {}".format(pi))

        pool.terminate()
        pool.join()
コード例 #3
0
ファイル: test_pool.py プロジェクト: zzszmyf/fiber
    def test_pool_more(self):
        pool = Pool(4)
        res = pool.map(f, [i for i in range(1000)])

        pool.wait_until_workers_up()

        pool.terminate()
        pool.join()
        assert res == [i**2 for i in range(1000)]
コード例 #4
0
ファイル: test_pool.py プロジェクト: zw0610/fiber
    def test_pool_more(self):
        pool = Pool(4)

        # explicitly start workers instead of lazy start
        pool.start_workers()
        res = pool.map(f, [i for i in range(1000)])

        pool.wait_until_workers_up()

        pool.terminate()
        pool.join()
        assert res == [i**2 for i in range(1000)]
コード例 #5
0
ファイル: test_pool.py プロジェクト: zw0610/fiber
    def test_pool_multiple_workers_inside_one_job(self):
        old_val = fiber_config.cpu_per_job
        try:
            fiber_config.cpu_per_job = 2
            pool = Pool(4)
            # explicitly start workers instead of lazy start
            pool.start_workers()
            # wait for all the workers to start
            pool.wait_until_workers_up()

            res = pool.map(get_proc_name, [i for i in range(4)], chunksize=1)
            pool.terminate()
            pool.join()
            res.sort()
            # Two `ForkProcess-1` from 2 jobs, two `ForkProcess-2` from the first job
            assert res == ['ForkProcess-1', 'ForkProcess-1', 'ForkProcess-2', 'ForkProcess-2'], res
        finally:
            fiber_config.cpu_per_job = old_val
コード例 #6
0
ファイル: pi_estimation.py プロジェクト: bigeyesung/fiber
def main():
    pool = Pool(processes=8)
    pi = 4.0 * sum(pool.map(is_inside, range(0, NUM_SAMPLES))) / NUM_SAMPLES
    print("Pi is roughly {}".format(pi))
コード例 #7
0
ファイル: test_pool.py プロジェクト: zw0610/fiber
 def test_pool_basic(self):
     pool = Pool(2)
     res = pool.map(f, [1, 2, 3])
     pool.terminate()
     pool.join()
     assert res == [1, 4, 9]