MCPcopy Create free account
hub / github.com/apache/arrow / test_interrupt

Function test_interrupt

python/pyarrow/tests/test_flight.py:2403–2444  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2401
2402@pytest.mark.threading
2403def test_interrupt():
2404 if threading.current_thread().ident != threading.main_thread().ident:
2405 pytest.skip("test only works from main Python thread")
2406
2407 def signal_from_thread():
2408 time.sleep(0.5)
2409 signal.raise_signal(signal.SIGINT)
2410
2411 exc_types = (KeyboardInterrupt, pa.ArrowCancelled)
2412
2413 def test(read_all):
2414 try:
2415 try:
2416 t = threading.Thread(target=signal_from_thread)
2417 with pytest.raises(exc_types) as exc_info:
2418 t.start()
2419 read_all()
2420 finally:
2421 t.join()
2422 except KeyboardInterrupt:
2423 # In case KeyboardInterrupt didn't interrupt read_all
2424 # above, at least prevent it from stopping the test suite
2425 pytest.fail("KeyboardInterrupt didn't interrupt Flight read_all")
2426 # __context__ is sometimes None
2427 e = exc_info.value
2428 assert isinstance(e, (pa.ArrowCancelled, KeyboardInterrupt)) or \
2429 isinstance(e.__context__, (pa.ArrowCancelled, KeyboardInterrupt))
2430
2431 with CancelFlightServer() as server, \
2432 FlightClient(("localhost", server.port)) as client:
2433
2434 reader = client.do_get(flight.Ticket(b""))
2435 test(reader.read_all)
2436
2437 descriptor = flight.FlightDescriptor.for_command(b"echo")
2438 writer, reader = client.do_exchange(descriptor)
2439 test(reader.read_all)
2440 try:
2441 writer.close()
2442 except (KeyboardInterrupt, flight.FlightCancelledError):
2443 # Silence the Cancelled/Interrupt exception
2444 pass
2445
2446
2447def test_never_sends_data():

Callers

nothing calls this directly

Calls 6

FlightClientClass · 0.90
CancelFlightServerClass · 0.85
testFunction · 0.85
do_getMethod · 0.45
do_exchangeMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected