summaryrefslogtreecommitdiff
path: root/numpy/core/arrayprint.py
diff options
context:
space:
mode:
authorEric Wieser <wieser.eric@gmail.com>2018-02-19 00:17:03 -0800
committerGitHub <noreply@github.com>2018-02-19 00:17:03 -0800
commit71555c48be7f07833bd540dacb50deb8069b551f (patch)
tree62b83ac79df5fb1cbfdc6ac4b25e233c1fb980f8 /numpy/core/arrayprint.py
parentbd7919ad34bf8fe94a239c4c76873db7fdc656db (diff)
parent50fde71f1ac0528f40ee216136b33fde41205ef2 (diff)
downloadnumpy-71555c48be7f07833bd540dacb50deb8069b551f.tar.gz
Merge pull request #10621 from ahaldane/fix_arrayprint_recursive_closure
BUG: deallocate recursive closure in arrayprint.py
Diffstat (limited to 'numpy/core/arrayprint.py')
-rw-r--r--numpy/core/arrayprint.py19
1 files changed, 12 insertions, 7 deletions
diff --git a/numpy/core/arrayprint.py b/numpy/core/arrayprint.py
index 84943cafc..cbe95f51b 100644
--- a/numpy/core/arrayprint.py
+++ b/numpy/core/arrayprint.py
@@ -772,7 +772,8 @@ def _formatArray(a, format_function, line_width, next_line_prefix,
s += hanging_indent + summary_insert + line_sep
for i in range(trailing_items, 1, -1):
- nested = recurser(index + (-i,), next_hanging_indent, next_width)
+ nested = recurser(index + (-i,), next_hanging_indent,
+ next_width)
s += hanging_indent + nested + line_sep
nested = recurser(index + (-1,), next_hanging_indent, next_width)
@@ -782,12 +783,16 @@ def _formatArray(a, format_function, line_width, next_line_prefix,
s = '[' + s[len(hanging_indent):] + ']'
return s
- # invoke the recursive part with an initial index and prefix
- return recurser(
- index=(),
- hanging_indent=next_line_prefix,
- curr_width=line_width)
-
+ try:
+ # invoke the recursive part with an initial index and prefix
+ return recurser(index=(),
+ hanging_indent=next_line_prefix,
+ curr_width=line_width)
+ finally:
+ # recursive closures have a cyclic reference to themselves, which
+ # requires gc to collect (gh-10620). To avoid this problem, for
+ # performance and PyPy friendliness, we break the cycle:
+ recurser = None
def _none_or_positive_arg(x, name):
if x is None: