コード例 #1
0
 def test_multiple_executors(self):
     executor1 = futures.MPIPoolExecutor(1).bootup(wait=True)
     executor2 = futures.MPIPoolExecutor(1).bootup(wait=True)
     executor3 = futures.MPIPoolExecutor(1).bootup(wait=True)
     fs1 = [executor1.submit(abs, i) for i in range(100, 200)]
     fs2 = [executor2.submit(abs, i) for i in range(200, 300)]
     fs3 = [executor3.submit(abs, i) for i in range(300, 400)]
     futures.wait(fs3 + fs2 + fs1)
     for i, f in enumerate(fs1):
         self.assertEqual(f.result(), i + 100)
     for i, f in enumerate(fs2):
         self.assertEqual(f.result(), i + 200)
     for i, f in enumerate(fs3):
         self.assertEqual(f.result(), i + 300)
     executor1 = executor2 = executor3 = None
コード例 #2
0
ファイル: test_futures.py プロジェクト: mpi4py/mpi4py
 def test_multiple_executors(self):
     executor1 = futures.MPIPoolExecutor(1).bootup(wait=True)
     executor2 = futures.MPIPoolExecutor(1).bootup(wait=True)
     executor3 = futures.MPIPoolExecutor(1).bootup(wait=True)
     fs1 = [executor1.submit(abs, i) for i in range(100, 200)]
     fs2 = [executor2.submit(abs, i) for i in range(200, 300)]
     fs3 = [executor3.submit(abs, i) for i in range(300, 400)]
     futures.wait(fs3+fs2+fs1)
     for i, f in enumerate(fs1):
         self.assertEqual(f.result(), i + 100)
     for i, f in enumerate(fs2):
         self.assertEqual(f.result(), i + 200)
     for i, f in enumerate(fs3):
         self.assertEqual(f.result(), i + 300)
     executor1 = executor2 = executor3 = None
コード例 #3
0
    def test_first_exception_one_already_failed(self):
        future1 = self.executor.submit(time.sleep, 0.2)

        finished, pending = futures.wait([EXCEPTION_FUTURE, future1],
                                         return_when=futures.FIRST_EXCEPTION)

        self.assertEqual(set([EXCEPTION_FUTURE]), finished)
        self.assertEqual(set([future1]), pending)
コード例 #4
0
    def test_first_completed(self):
        future1 = self.executor.submit(mul, 21, 2)
        future2 = self.executor.submit(time.sleep, 0.2)

        done, not_done = futures.wait([CANCELLED_FUTURE, future1, future2],
                                      return_when=futures.FIRST_COMPLETED)

        self.assertEqual(set([future1]), done)
        self.assertEqual(set([CANCELLED_FUTURE, future2]), not_done)
コード例 #5
0
ファイル: test_futures.py プロジェクト: mpi4py/mpi4py
    def test_first_exception_one_already_failed(self):
        future1 = self.executor.submit(time.sleep, 0.2)

        finished, pending = futures.wait(
                 [EXCEPTION_FUTURE, future1],
                 return_when=futures.FIRST_EXCEPTION)

        self.assertEqual(set([EXCEPTION_FUTURE]), finished)
        self.assertEqual(set([future1]), pending)
コード例 #6
0
    def test_first_exception(self):
        future1 = self.executor.submit(mul, 2, 21)
        future2 = self.executor.submit(sleep_and_raise, 0.2)
        future3 = self.executor.submit(time.sleep, 0.4)

        finished, pending = futures.wait([future1, future2, future3],
                                         return_when=futures.FIRST_EXCEPTION)

        self.assertEqual(set([future1, future2]), finished)
        self.assertEqual(set([future3]), pending)
コード例 #7
0
    def test_first_completed_some_already_completed(self):
        future1 = self.executor.submit(time.sleep, 0.2)

        finished, pending = futures.wait(
            [CANCELLED_AND_NOTIFIED_FUTURE, SUCCESSFUL_FUTURE, future1],
            return_when=futures.FIRST_COMPLETED)

        self.assertEqual(
            set([CANCELLED_AND_NOTIFIED_FUTURE, SUCCESSFUL_FUTURE]), finished)
        self.assertEqual(set([future1]), pending)
コード例 #8
0
ファイル: test_futures.py プロジェクト: mpi4py/mpi4py
    def test_first_completed(self):
        future1 = self.executor.submit(mul, 21, 2)
        future2 = self.executor.submit(time.sleep, 0.2)

        done, not_done = futures.wait(
                [CANCELLED_FUTURE, future1, future2],
                return_when=futures.FIRST_COMPLETED)

        self.assertEqual(set([future1]), done)
        self.assertEqual(set([CANCELLED_FUTURE, future2]), not_done)
コード例 #9
0
ファイル: test_futures.py プロジェクト: mpi4py/mpi4py
    def test_first_exception(self):
        future1 = self.executor.submit(mul, 2, 21)
        future2 = self.executor.submit(sleep_and_raise, 0.2)
        future3 = self.executor.submit(time.sleep, 0.4)

        finished, pending = futures.wait(
                [future1, future2, future3],
                return_when=futures.FIRST_EXCEPTION)

        self.assertEqual(set([future1, future2]), finished)
        self.assertEqual(set([future3]), pending)
コード例 #10
0
ファイル: test_futures.py プロジェクト: mpi4py/mpi4py
    def test_first_completed_some_already_completed(self):
        future1 = self.executor.submit(time.sleep, 0.2)

        finished, pending = futures.wait(
                 [CANCELLED_AND_NOTIFIED_FUTURE, SUCCESSFUL_FUTURE, future1],
                 return_when=futures.FIRST_COMPLETED)

        self.assertEqual(
                set([CANCELLED_AND_NOTIFIED_FUTURE, SUCCESSFUL_FUTURE]),
                finished)
        self.assertEqual(set([future1]), pending)
コード例 #11
0
    def test_first_exception_some_already_complete(self):
        future1 = self.executor.submit(divmod, 21, 0)
        future2 = self.executor.submit(time.sleep, 0.2)

        finished, pending = futures.wait([
            SUCCESSFUL_FUTURE, CANCELLED_FUTURE, CANCELLED_AND_NOTIFIED_FUTURE,
            future1, future2
        ],
                                         return_when=futures.FIRST_EXCEPTION)

        self.assertEqual(
            set([SUCCESSFUL_FUTURE, CANCELLED_AND_NOTIFIED_FUTURE, future1]),
            finished)
        self.assertEqual(set([CANCELLED_FUTURE, future2]), pending)
コード例 #12
0
ファイル: test_futures.py プロジェクト: mpi4py/mpi4py
    def test_first_exception_some_already_complete(self):
        future1 = self.executor.submit(divmod, 21, 0)
        future2 = self.executor.submit(time.sleep, 0.2)

        finished, pending = futures.wait(
                [SUCCESSFUL_FUTURE,
                 CANCELLED_FUTURE,
                 CANCELLED_AND_NOTIFIED_FUTURE,
                 future1, future2],
                return_when=futures.FIRST_EXCEPTION)

        self.assertEqual(set([SUCCESSFUL_FUTURE,
                              CANCELLED_AND_NOTIFIED_FUTURE,
                              future1]), finished)
        self.assertEqual(set([CANCELLED_FUTURE, future2]), pending)
コード例 #13
0
    def test_all_completed(self):
        future1 = self.executor.submit(divmod, 2, 0)
        future2 = self.executor.submit(mul, 2, 21)

        finished, pending = futures.wait([
            SUCCESSFUL_FUTURE, CANCELLED_AND_NOTIFIED_FUTURE, EXCEPTION_FUTURE,
            future1, future2
        ],
                                         return_when=futures.ALL_COMPLETED)

        self.assertEqual(
            set([
                SUCCESSFUL_FUTURE, CANCELLED_AND_NOTIFIED_FUTURE,
                EXCEPTION_FUTURE, future1, future2
            ]), finished)
        self.assertEqual(set(), pending)
コード例 #14
0
    def test_timeout(self):
        future1 = self.executor.submit(mul, 6, 7)
        future2 = self.executor.submit(time.sleep, 0.5)

        finished, pending = futures.wait([
            CANCELLED_AND_NOTIFIED_FUTURE, EXCEPTION_FUTURE, SUCCESSFUL_FUTURE,
            future1, future2
        ],
                                         timeout=0.2,
                                         return_when=futures.ALL_COMPLETED)

        self.assertEqual(
            set([
                CANCELLED_AND_NOTIFIED_FUTURE, EXCEPTION_FUTURE,
                SUCCESSFUL_FUTURE, future1
            ]), finished)
        self.assertEqual(set([future2]), pending)
コード例 #15
0
ファイル: test_futures.py プロジェクト: mpi4py/mpi4py
    def test_timeout(self):
        future1 = self.executor.submit(mul, 6, 7)
        future2 = self.executor.submit(time.sleep, 0.5)

        finished, pending = futures.wait(
                [CANCELLED_AND_NOTIFIED_FUTURE,
                 EXCEPTION_FUTURE,
                 SUCCESSFUL_FUTURE,
                 future1, future2],
                timeout=0.2,
                return_when=futures.ALL_COMPLETED)

        self.assertEqual(set([CANCELLED_AND_NOTIFIED_FUTURE,
                              EXCEPTION_FUTURE,
                              SUCCESSFUL_FUTURE,
                              future1]), finished)
        self.assertEqual(set([future2]), pending)
コード例 #16
0
ファイル: test_futures.py プロジェクト: mpi4py/mpi4py
    def test_all_completed(self):
        future1 = self.executor.submit(divmod, 2, 0)
        future2 = self.executor.submit(mul, 2, 21)

        finished, pending = futures.wait(
                [SUCCESSFUL_FUTURE,
                 CANCELLED_AND_NOTIFIED_FUTURE,
                 EXCEPTION_FUTURE,
                 future1,
                 future2],
                return_when=futures.ALL_COMPLETED)

        self.assertEqual(set([SUCCESSFUL_FUTURE,
                              CANCELLED_AND_NOTIFIED_FUTURE,
                              EXCEPTION_FUTURE,
                              future1,
                              future2]), finished)
        self.assertEqual(set(), pending)