def test_lifecycle_2(self): def run(): time.sleep(0.25) raise ValueError("lifecycle 2") thread = Thread(target=run) thread.daemon = True thread.start()
def test_raise_error_join(self): def run(): time.sleep(0.5) raise ValueError("raise_error_join") thread = Thread(target=run) thread.start() with self.assertRaises(ValueError): thread.join()
def test_success(self): q = queue.Queue() def run(): q.put(2) thread = Thread(target=run) thread.start() thread.join() self.assertEqual(2, q.get(False))
def test_raise_error_start(self): def run(): raise ValueError("raise_error_start") thread = Thread(target=run) with self.assertRaises(KeyboardInterrupt): thread.start() while thread.is_alive(): time.sleep(0.1) self.assertIsInstance(thread.exception, ValueError)
def test_lifecycle_1(self): def run(): time.sleep(0.25) raise ValueError("lifecycle 1") thread = Thread(target=run) thread.daemon = True thread.start() while not thread.exception: pass pout.v(thread.exception)
def test_raise_error_daemon_join(self): def run(): time.sleep(0.5) raise ValueError("raise_error_daemon_join") thread = Thread(target=run) thread.daemon = True thread.start() with self.assertRaises(ValueError): thread.join()
def test_join_2(self): def run(): time.sleep(0.5) raise ValueError("join_2") thread = Thread(target=run) thread.daemon = True thread.start() try: thread.join() except ValueError as e: self.assertEqual("join_2", str(e))