8000 DEV, BUILD: add pypy3 to azure CI by mattip · Pull Request #12594 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

DEV, BUILD: add pypy3 to azure CI #12594

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 22, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
MAINT: move gc.collect to function (from review)
  • Loading branch information
mattip committed Apr 19, 2019
commit a641ef245a9f8d320fac5cdea5632649db5fab4a
16 changes: 8 additions & 8 deletions numpy/core/tests/test_multiarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
assert_, assert_raises, assert_warns, assert_equal, assert_almost_equal,
assert_array_equal, assert_raises_regex, assert_array_almost_equal,
assert_allclose, IS_PYPY, HAS_REFCOUNT, assert_array_less, runstring,
temppath, suppress_warnings
temppath, suppress_warnings, break_cycles,
)
from numpy.core.tests._locales import CommaDecimalPointLocale

Expand Down Expand Up @@ -3784,7 +3784,7 @@ def test_roundtrip(self):
a, pickle.loads(pickle.dumps(a, protocol=proto)),
err_msg="%r" % a)
del a, DATA, carray
gc.collect(); gc.collect(); gc.collect()
break_cycles()
# check for reference leaks (gh-12793)
for ref in refs:
assert ref() is None
Expand Down Expand Up @@ -7181,7 +7181,7 @@ def test_mem_seteventhook(self):
# needs to be larger then limit of small memory cacher in ctors.c
a = np.zeros(1000)
del a
gc.collect(); gc.collect(); gc.collect()
break_cycles()
_multiarray_tests.test_pydatamem_seteventhook_end()

class TestMapIter(object):
Expand Down Expand Up @@ -7753,12 +7753,12 @@ def test_ctypes_data_as_holds_reference(self, arr):

# `ctypes_ptr` should hold onto `arr`
del arr
gc.collect(); gc.collect(); gc.collect()
break_cycles()
assert_(arr_ref() is not None, "ctypes pointer did not hold onto a reference")

# but when the `ctypes_ptr` object dies, so should `arr`
del ctypes_ptr
gc.collect(); gc.collect(); gc.collect()
break_cycles()
assert_(arr_ref() is None, "unknowable whether ctypes pointer holds a reference")


Expand Down Expand Up @@ -7940,15 +7940,15 @@ class Dummy(object): pass
assert_(isinstance(obj_subarray, RaisesInFinalize))

# reference should still be held by obj_arr
gc.collect(); gc.collect(); gc.collect()
break_cycles()
assert_(obj_ref() is not None, "object should not already be dead")

del obj_arr
gc.collect(); gc.collect(); gc.collect()
break_cycles()
assert_(obj_ref() is not None, "obj_arr should not hold the last reference")

del obj_subarray
gc.collect(); gc.collect(); gc.collect()
break_cycles()
assert_(obj_ref() is None, "no references should remain")


Expand Down
20 changes: 19 additions & 1 deletion numpy/testing/_private/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import os
import sys
import platform
import re
import gc
import operator
Expand Down Expand Up @@ -39,6 +40,7 @@
'SkipTest', 'KnownFailureException', 'temppath', 'tempdir', 'IS_PYPY',
'HAS_REFCOUNT', 'suppress_warnings', 'assert_array_compare',
'_assert_valid_refcount', '_gen_alignment_data', 'assert_no_gc_cycles',
'break_cycles',
]


Expand All @@ -50,7 +52,7 @@ class KnownFailureException(Exception):
KnownFailureTest = KnownFailureException # backwards compat
verbose = 0

IS_PYPY = '__pypy__' in sys.modules
IS_PYPY = platform.python_implementation() == 'PyPy'
HAS_REFCOUNT = getattr(sys, 'getrefcount', None) is not None


Expand Down Expand Up @@ -2324,3 +2326,19 @@ def assert_no_gc_cycles(*args, **kwargs):
args = args[1:]
with _assert_no_gc_cycles_context(name=func.__name__):
func(*args, **kwargs)

def break_cycles():
"""
Break reference cycles by calling gc.collect
Objects can call other objects' methods (for instance, another object's
__del__) inside their own __del__. On PyPy, the interpreter only runs
between calls to gc.collect, so multiple calls are needed to completely
release all cycles.
"""

gc.collect()
if IS_PYPY:
# interpreter runs now, to call deleted objects' __del__ methods
gc.collect()
# one more, just to make sure
gc.collect()
4 changes: 4 additions & 0 deletions tools/pypy-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ mkdir -p pypy3
pypy3/bin/pypy3 -mensurepip
pypy3/bin/pypy3 -m pip install --upgrade pip setuptools
pypy3/bin/pypy3 -m pip install --user cython==0.29.0 pytest pytz --no-warn-script-location
echo
echo pypy3 version
pypy3/bin/pypy3 -c "import sys; print(sys.version)"
echo
pypy3/bin/pypy3 runtests.py -- -rsx --junitxml=junit/test-results.xml --durations 10
0