diff --git a/python/pyarrow/error.pxi b/python/pyarrow/error.pxi index cbe25522e8d..3e01d0d57f8 100644 --- a/python/pyarrow/error.pxi +++ b/python/pyarrow/error.pxi @@ -19,15 +19,12 @@ from cpython.exc cimport PyErr_CheckSignals, PyErr_SetInterrupt from pyarrow.includes.libarrow cimport CStatus from pyarrow.includes.libarrow_python cimport IsPyError, RestorePyError -from pyarrow.includes.common cimport c_string -from contextlib import contextmanager import os import signal import threading from pyarrow.lib import is_threading_enabled -from pyarrow.util import _break_traceback_cycle_from_frame class ArrowException(Exception): @@ -188,11 +185,6 @@ def enable_signal_handlers(c_bool enable): # For internal use -# Whether we need a workaround for https://bugs.python.org/issue42248 -have_signal_refcycle = (sys.version_info < (3, 8, 10) or - (3, 9) <= sys.version_info < (3, 9, 5) or - sys.version_info[:2] == (3, 10)) - cdef class SignalStopHandler: cdef: StopToken _stop_token @@ -203,9 +195,6 @@ cdef class SignalStopHandler: self._enabled = False self._init_signals() - if have_signal_refcycle: - _break_traceback_cycle_from_frame(sys._getframe(0)) - self._stop_token = StopToken() if not self._signals.empty(): diff --git a/python/pyarrow/tests/test_util.py b/python/pyarrow/tests/test_util.py index c5d58de04c4..038855429eb 100644 --- a/python/pyarrow/tests/test_util.py +++ b/python/pyarrow/tests/test_util.py @@ -15,19 +15,14 @@ # specific language governing permissions and limitations # under the License. -import gc import os -import signal import shutil import sys import textwrap -import weakref import pytest -from pyarrow.util import (doc, _break_traceback_cycle_from_frame, - download_tzdata_on_windows) -from pyarrow.tests.util import disabled_gc +from pyarrow.util import doc, download_tzdata_on_windows @doc(method="func_a", operation="A") @@ -186,32 +181,6 @@ def test_escaping_in_docstring(): assert func_f.__doc__ == docstr -def exhibit_signal_refcycle(): - # Put an object in the frame locals and return a weakref to it. - # If `signal.getsignal` has a bug where it creates a reference cycle - # keeping alive the current execution frames, `obj` will not be - # destroyed immediately when this function returns. - obj = set() - signal.getsignal(signal.SIGINT) - return weakref.ref(obj) - - -def test_signal_refcycle(): - # Test possible workaround for https://bugs.python.org/issue42248 - with disabled_gc(): - wr = exhibit_signal_refcycle() - if wr() is None: - pytest.skip( - "Python version does not have the bug we're testing for") - - gc.collect() - with disabled_gc(): - wr = exhibit_signal_refcycle() - assert wr() is not None - _break_traceback_cycle_from_frame(sys._getframe(0)) - assert wr() is None - - @pytest.mark.skipif(sys.platform != "win32", reason="Timezone database is already provided.") def test_download_tzdata_on_windows(): diff --git a/python/pyarrow/util.py b/python/pyarrow/util.py index 48c28069238..f4dc83e9b29 100644 --- a/python/pyarrow/util.py +++ b/python/pyarrow/util.py @@ -20,11 +20,9 @@ import os import contextlib import functools -import gc import socket import sys import textwrap -import types import warnings @@ -207,29 +205,6 @@ def guid(): return uuid4().hex -def _break_traceback_cycle_from_frame(frame): - # Clear local variables in all inner frames, so as to break the - # reference cycle. - this_frame = sys._getframe(0) - refs = gc.get_referrers(frame) - while refs: - for frame in refs: - if frame is not this_frame and isinstance(frame, types.FrameType): - break - else: - # No frame found in referrers (finished?) - break - refs = None - # Clear the frame locals, to try and break the cycle (it is - # somewhere along the chain of execution frames). - frame.clear() - # To visit the inner frame, we need to find it among the - # referrers of this frame (while `frame.f_back` would let - # us visit the outer frame). - refs = gc.get_referrers(frame) - refs = frame = this_frame = None - - def _download_urllib(url, out_path): from urllib.request import urlopen, Request req = Request(url, headers={'User-Agent': 'pyarrow'})