From 7717af4c1228534a9d84cbc188df8ae241d266d7 Mon Sep 17 00:00:00 2001 From: David Li Date: Mon, 3 May 2021 09:56:33 -0400 Subject: [PATCH] ARROW-12622: [Python] Fix read_csv when not on main thread --- python/pyarrow/error.pxi | 2 +- python/pyarrow/tests/test_csv.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/python/pyarrow/error.pxi b/python/pyarrow/error.pxi index f9e45f238df..2866848272a 100644 --- a/python/pyarrow/error.pxi +++ b/python/pyarrow/error.pxi @@ -188,8 +188,8 @@ cdef class SignalStopHandler: if signal.getsignal(sig) not in (signal.SIG_DFL, signal.SIG_IGN, None)] + self._stop_token = StopToken() if not self._signals.empty(): - self._stop_token = StopToken() self._stop_token.init(GetResultValue( SetSignalStopSource()).token()) self._enabled = True diff --git a/python/pyarrow/tests/test_csv.py b/python/pyarrow/tests/test_csv.py index 395f9486315..34ab556b769 100644 --- a/python/pyarrow/tests/test_csv.py +++ b/python/pyarrow/tests/test_csv.py @@ -942,6 +942,14 @@ def signal_from_thread(): assert isinstance(e, pa.ArrowCancelled) assert e.signum == signal.SIGINT + def test_cancellation_disabled(self): + # ARROW-12622: reader would segfault when the cancelling signal + # handler was not enabled (e.g. if disabled, or if not on the + # main thread) + t = threading.Thread(target=lambda: self.read_bytes(b"f64\n0.1")) + t.start() + t.join() + class TestSerialCSVRead(BaseTestCSVRead, unittest.TestCase):