Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions python/pyarrow/error.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand All @@ -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():
Expand Down
33 changes: 1 addition & 32 deletions python/pyarrow/tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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():
Expand Down
25 changes: 0 additions & 25 deletions python/pyarrow/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@
import os
import contextlib
import functools
import gc
import socket
import sys
import textwrap
import types
import warnings


Expand Down Expand Up @@ -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'})
Expand Down
Loading