Example #1
0
 def test_exception_single(self):
     nprocs = 2
     for i in range(nprocs):
         with self.assertRaisesRegex(
                 Exception,
                 "\nValueError: legitimate exception from process %d$" % i):
             spawn(test_exception_single_func, (i, ), nprocs=nprocs)
Example #2
0
 def test_terminate_exit(self, mock_get_error):
     exitcode = 123
     subprocess_error_msg = "some_error_msg\n\n2333\ntrace:\n\n(fds)"
     mock_get_error.return_value = subprocess_error_msg
     with self.assertRaises(WorkerExitedException) as cm:
         spawn(test_terminate_exit_func, (exitcode, ), nprocs=2)
         self.assertTrue(subprocess_error_msg in str(cm))
         self.assertEqual(exitcode, cm.exception.exit_code)
         self.assertEqual(0, cm.exception.error_index)
Example #3
0
    def test_terminate_signal(self, mock_get_error):
        subprocess_error_msg = (
            '*** Aborted at 1225095260 (unix time) try "date -d @1225095260" if you are using GNU date ***'
            "*** SIGABRT (@0x0) received by PID 17711 (TID 0x7f893090a6f0) from PID 0; stack trace: ***"
            "PC: @           0x412eb1 TestWaitingLogSink::send()"
            "    @     0x7f892fb417d0 (unknown)")
        mock_get_error.return_value = subprocess_error_msg
        with self.assertRaises(WorkerSignaledException) as cm:
            spawn(test_terminate_signal_func, (), nprocs=2)
            self.assertTrue(subprocess_error_msg in str(cm))

        self.assertEqual("SIGABRT", cm.exception.signal_name)
        self.assertEqual(0, cm.exception.error_index)
Example #4
0
    def test_success_non_blocking(self):
        spawn_context = spawn(test_success_func, nprocs=2, join=False)

        # After all processes (nproc=2) have joined it must return True
        spawn_context.join(timeout=None)
        spawn_context.join(timeout=None)
        self.assertTrue(spawn_context.join(timeout=None))
Example #5
0
 def test_exception_all(self):
     with self.assertRaisesRegex(
             Exception,
             "\nValueError: legitimate exception from process (0|1)$"):
         spawn(test_exception_all_func, (), nprocs=2)
Example #6
0
 def test_first_argument_index(self):
     mp = multiprocessing.get_context("spawn")
     queue = mp.SimpleQueue()
     spawn(test_success_func, (queue, ), nprocs=2)
     self.assertEqual([0, 1], sorted([queue.get(), queue.get()]))
Example #7
0
 def test_success(self):
     spawn(test_success_func, nprocs=2)
Example #8
0
 def test_success_first_then_exception(self):
     exitcode = 123
     with self.assertRaisesRegex(Exception,
                                 "ValueError: legitimate exception"):
         spawn(test_success_first_then_exception_func, (exitcode, ),
               nprocs=2)
Example #9
0
 def test_exception_single(self):
     nprocs = 2
     with self.assertRaisesRegex(
             Exception,
             "\nValueError: legitimate exception from process 0"):
         spawn(test_exception_single_func, (0, ), nprocs=nprocs)