| 1 |
"""Minimal script to reproduce our nasty reference counting bug. |
| 2 |
|
| 3 |
The problem is related to https://github.com/ipython/ipython/issues/141 |
| 4 |
|
| 5 |
The original fix for that appeared to work, but John D. Hunter found a |
| 6 |
matplotlib example which, when run twice in a row, would break. The problem |
| 7 |
were references held by open figures to internals of Tkinter. |
| 8 |
|
| 9 |
This code reproduces the problem that John saw, without matplotlib. |
| 10 |
|
| 11 |
This script is meant to be called by other parts of the test suite that call it |
| 12 |
via %run as if it were executed interactively by the user. As of 2011-05-29, |
| 13 |
test_run.py calls it. |
| 14 |
""" |
| 15 |
|
| 16 |
# ----------------------------------------------------------------------------- |
| 17 |
# Module imports |
| 18 |
# ----------------------------------------------------------------------------- |
| 19 |
|
| 20 |
from IPython import get_ipython |
| 21 |
|
| 22 |
# ----------------------------------------------------------------------------- |
| 23 |
# Globals |
| 24 |
# ----------------------------------------------------------------------------- |
| 25 |
|
| 26 |
# This needs to be here because nose and other test runners will import |
| 27 |
# this module. Importing this module has potential side effects that we |
| 28 |
# want to prevent. |
| 29 |
if __name__ == "__main__": |
| 30 |
ip = get_ipython() |
| 31 |
|
| 32 |
if not "_refbug_cache" in ip.user_ns: |
| 33 |
ip.user_ns["_refbug_cache"] = [] |
| 34 |
|
| 35 |
aglobal = "Hello" |
| 36 |
|
| 37 |
def f(): |
| 38 |
return aglobal |
| 39 |
|
| 40 |
cache = ip.user_ns["_refbug_cache"] |
| 41 |
cache.append(f) |
| 42 |
|
| 43 |
def call_f(): |
| 44 |
for func in cache: |
| 45 |
print("lowercased:", func().lower()) |