Skip to content

Commit

Permalink
Further fix for #313 for IPython/Juypter
Browse files Browse the repository at this point in the history
  • Loading branch information
robbmcleod committed Aug 16, 2018
1 parent f0ab31f commit 742628e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
13 changes: 8 additions & 5 deletions numexpr/necompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -725,15 +725,18 @@ def getArguments(names, local_dict=None, global_dict=None):
"""Get the arguments based on the names."""
call_frame = sys._getframe(2)

# If `call_frame` is the top frame of the interpreter we can't clear its
# `local_dict`, because it is actually the `global_dict`.
clear_local_dict = (local_dict is None) and (call_frame.f_back is not None)

clear_local_dict = False
if local_dict is None:
local_dict = call_frame.f_locals
clear_local_dict = True
try:
frame_globals = call_frame.f_globals
if global_dict is None:
global_dict = call_frame.f_globals
global_dict = frame_globals

# If `call_frame` is the top frame of the interpreter we can't clear its
# `local_dict`, because it is actually the `global_dict`.
clear_local_dict = clear_local_dict and not frame_globals is local_dict

arguments = []
for name in names:
Expand Down
11 changes: 11 additions & 0 deletions numexpr/tests/test_numexpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,19 @@ def test_refcount(self):
assert sys.getrefcount(a) == 2

# Regression test for #313, ensure that globals is never `.clear`'d
# accidently when trying to remove the extraneous reference count
# the call to f_locals generates.
issue313 += '.'

# Try permutations of providing `local_dict` and `global_dict`
evaluate('2+2', local_dict={})
issue313 += '.'
evaluate('3+3', global_dict={})
issue313 += '.'
evaluate('4+4', local_dict={}, global_dict={})
issue313 += '.'



class test_numexpr2(test_numexpr):
"""Testing with 2 threads"""
Expand Down

0 comments on commit 742628e

Please sign in to comment.