From 5118635d97b5c356dce067ffb0bfc630a74dd4e0 Mon Sep 17 00:00:00 2001 From: Taewoon Kim Date: Fri, 27 Nov 2026 18:12:44 +0900 Subject: [PATCH] test: keep the interrupt test's own Ctrl-C inside its try The timer was started before the try, and its cancel and join ran in a finally, so a signal raised while the main thread waited in start() or in the cleanup left the test and stopped the whole pytest run (seen once on main, linux/amd64, Python 3.13, run 45959878115). Both loops (in process and in the child process) now catch it wherever it is raised from start() on. Closes #512 --- tests/test_python_function_interrupt.py | 39 ++++++++++--------------- 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/tests/test_python_function_interrupt.py b/tests/test_python_function_interrupt.py index eeddd75f..019efa52 100644 --- a/tests/test_python_function_interrupt.py +++ b/tests/test_python_function_interrupt.py @@ -57,21 +57,17 @@ def test_sigint_during_a_query_that_calls_python_is_a_keyboard_interrupt( interrupted = 0 for delay in (0.05, 0.09, 0.13, 0.17, 0.21, 0.25, 0.29, 0.33): timer = threading.Timer(delay, os.kill, (os.getpid(), signal.SIGINT)) - timer.start() + # everything from start() on is inside this try: an escaped signal would stop the whole test run (#512) try: - db.query("sql", "SELECT sum(plus_one(n)) AS s FROM T").first() - outcome = "completed" + try: + timer.start() + db.query("sql", "SELECT sum(plus_one(n)) AS s FROM T").first() + finally: + timer.cancel() + timer.join() + time.sleep(0.05) # a signal sent just after the end is delivered here except KeyboardInterrupt: - outcome = "interrupted" interrupted += 1 - finally: - timer.cancel() - timer.join() - if outcome == "completed": - try: # a signal sent just after the end is delivered here, still a KeyboardInterrupt - time.sleep(0.05) - except KeyboardInterrupt: - interrupted += 1 # the database works as before assert db.count_type("T") == 300_000 assert interrupted >= 1 @@ -123,21 +119,16 @@ def test_a_statement_that_fails_otherwise_is_still_an_arcadedb_error(db): interrupted = 0 for delay in (0.05, 0.15, 0.25, 0.35, 0.45, 0.55): timer = threading.Timer(delay, os.kill, (os.getpid(), signal.SIGINT)) - timer.start() try: - db.query("sql", "SELECT sum(plus_one(n)) AS s FROM T").first() - done = True + try: + timer.start() + db.query("sql", "SELECT sum(plus_one(n)) AS s FROM T").first() + finally: + timer.cancel() + timer.join() + time.sleep(0.05) except KeyboardInterrupt: - done = False interrupted += 1 - finally: - timer.cancel() - timer.join() - if done: - try: - time.sleep(0.05) - except KeyboardInterrupt: - interrupted += 1 assert db.count_type("T") == 150_000 db.close() print("interrupted", interrupted)