]> git.proxmox.com Git - ceph.git/blame - ceph/src/arrow/python/pyarrow/tests/test_util.py
import quincy 17.2.0
[ceph.git] / ceph / src / arrow / python / pyarrow / tests / test_util.py
CommitLineData
1d09f67e
TL
1# Licensed to the Apache Software Foundation (ASF) under one
2# or more contributor license agreements. See the NOTICE file
3# distributed with this work for additional information
4# regarding copyright ownership. The ASF licenses this file
5# to you under the Apache License, Version 2.0 (the
6# "License"); you may not use this file except in compliance
7# with the License. You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing,
12# software distributed under the License is distributed on an
13# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14# KIND, either express or implied. See the License for the
15# specific language governing permissions and limitations
16# under the License.
17
18import gc
19import signal
20import sys
21import weakref
22
23import pytest
24
25from pyarrow import util
26from pyarrow.tests.util import disabled_gc
27
28
29def exhibit_signal_refcycle():
30 # Put an object in the frame locals and return a weakref to it.
31 # If `signal.getsignal` has a bug where it creates a reference cycle
32 # keeping alive the current execution frames, `obj` will not be
33 # destroyed immediately when this function returns.
34 obj = set()
35 signal.getsignal(signal.SIGINT)
36 return weakref.ref(obj)
37
38
39def test_signal_refcycle():
40 # Test possible workaround for https://bugs.python.org/issue42248
41 with disabled_gc():
42 wr = exhibit_signal_refcycle()
43 if wr() is None:
44 pytest.skip(
45 "Python version does not have the bug we're testing for")
46
47 gc.collect()
48 with disabled_gc():
49 wr = exhibit_signal_refcycle()
50 assert wr() is not None
51 util._break_traceback_cycle_from_frame(sys._getframe(0))
52 assert wr() is None