Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 93eb52a

Browse files
committed
Add test that fails for reference counting problem
1 parent 17c694c commit 93eb52a

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

IPython/iplib.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1487,7 +1487,7 @@ def ask_yes_no(self,prompt,default=True):
14871487
return True
14881488
return ask_yes_no(prompt,default)
14891489

1490-
def cache_main_mod(self,mod):
1490+
def cache_main_mod(self,mod,fname=None):
14911491
"""Cache a main module.
14921492
14931493
When scripts are executed via %run, we must keep a reference to their
@@ -1515,7 +1515,10 @@ def cache_main_mod(self,mod):
15151515
In [12]: IPython.__file__ in _ip.IP._user_main_modules
15161516
Out[12]: True
15171517
"""
1518-
self._user_main_modules[os.path.abspath(mod.__file__) ] = mod
1518+
if fname is None:
1519+
fname = mod.__file__
1520+
#print >> sys.stderr, 'CFNAME :', os.path.abspath(fname) # dbg
1521+
self._user_main_modules[os.path.abspath(fname)] = mod
15191522

15201523
def clear_main_mod_cache(self):
15211524
"""Clear the cache of main modules.

IPython/tests/test_magic.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,19 @@ def test_fail_dec2(*a,**k):
131131
def test_fail_dec3(*a,**k):
132132
yield nt.assert_true, False
133133

134+
135+
def doctest_refbug():
136+
"""Very nasty problem with references held by multiple runs of a script.
137+
See: https://bugs.launchpad.net/ipython/+bug/269966
138+
139+
In [2]: run refbug
140+
141+
In [3]: call_f()
142+
lowercased: hello
143+
144+
In [4]: run refbug
145+
146+
In [5]: call_f()
147+
lowercased: hello
148+
lowercased: hello
149+
"""

0 commit comments

Comments
 (0)