# Buggy code
def reload(module, exclude=("sys", "os.path", builtin_mod_name, "__main__")):
    """Recursively reload all modules used in the given module.  Optionally
    takes a list of modules to exclude from reloading.  The default exclude
    list contains sys, __main__, and __builtin__, to prevent, e.g., resetting
    display, exception, and io hooks.
    """
    global found_now
    for i in exclude:
        found_now[i] = 1
    try:
        with replace_import_hook(deep_import_hook):
            return deep_reload_hook(module)
    finally:
        found_now = {}


# Traceback (nose.proxy.RuntimeError)
======================================================================
ERROR: Test that NumPy can be deep reloaded.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/var/lib/jenkins/shiningpanda/jobs/65e9266d/virtualenvs/d41d8cd9/lib/python3.4/site-packages/nose/case.py", line 198, in runTest
self.test(*self.arg)
File "/var/lib/jenkins/shiningpanda/jobs/65e9266d/virtualenvs/d41d8cd9/lib/python3.4/site-packages/IPython/testing/decorators.py", line 212, in skipper_func
return f(*args, **kwargs)
File "/var/lib/jenkins/shiningpanda/jobs/65e9266d/virtualenvs/d41d8cd9/lib/python3.4/site-packages/IPython/lib/tests/test_deepreload.py", line 38, in test_deepreload_numpy
dreload(numpy, exclude=exclude)
File "/var/lib/jenkins/shiningpanda/jobs/65e9266d/virtualenvs/d41d8cd9/lib/python3.4/site-packages/IPython/lib/deepreload.py", line 341, in reload
return deep_reload_hook(module)
File "/var/lib/jenkins/shiningpanda/jobs/65e9266d/virtualenvs/d41d8cd9/lib/python3.4/site-packages/IPython/lib/deepreload.py", line 311, in deep_reload_hook
newm = imp.load_module(name, fp, filename, stuff)
File "/var/lib/jenkins/shiningpanda/jobs/65e9266d/virtualenvs/d41d8cd9/lib/python3.4/imp.py", line 245, in load_module
return load_package(name, filename)
File "/var/lib/jenkins/shiningpanda/jobs/65e9266d/virtualenvs/d41d8cd9/lib/python3.4/imp.py", line 215, in load_package
return methods.exec(sys.modules[name])
File "<frozen importlib._bootstrap>", line 1153, in exec
File "<frozen importlib._bootstrap>", line 1129, in _exec
File "<frozen importlib._bootstrap>", line 1471, in exec_module
File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
File "/var/lib/jenkins/shiningpanda/jobs/65e9266d/virtualenvs/d41d8cd9/lib/python3.4/site-packages/numpy/__init__.py", line 112, in <module>
from ._globals import ModuleDeprecationWarning, VisibleDeprecationWarning
File "/var/lib/jenkins/shiningpanda/jobs/65e9266d/virtualenvs/d41d8cd9/lib/python3.4/site-packages/IPython/lib/deepreload.py", line 252, in deep_import_hook
head, name, buf = load_next(parent, None if level < 0 else parent, name, buf)
File "/var/lib/jenkins/shiningpanda/jobs/65e9266d/virtualenvs/d41d8cd9/lib/python3.4/site-packages/IPython/lib/deepreload.py", line 156, in load_next
result = import_submodule(mod, subname, buf)
File "/var/lib/jenkins/shiningpanda/jobs/65e9266d/virtualenvs/d41d8cd9/lib/python3.4/site-packages/IPython/lib/deepreload.py", line 201, in import_submodule
m = imp.load_module(fullname, fp, filename, stuff)
File "/var/lib/jenkins/shiningpanda/jobs/65e9266d/virtualenvs/d41d8cd9/lib/python3.4/imp.py", line 235, in load_module
return load_source(name, filename, file)
File "/var/lib/jenkins/shiningpanda/jobs/65e9266d/virtualenvs/d41d8cd9/lib/python3.4/imp.py", line 169, in load_source
module = methods.exec(sys.modules[name])
File "<frozen importlib._bootstrap>", line 1153, in exec
File "<frozen importlib._bootstrap>", line 1129, in _exec
File "<frozen importlib._bootstrap>", line 1471, in exec_module
File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
File "/var/lib/jenkins/shiningpanda/jobs/65e9266d/virtualenvs/d41d8cd9/lib/python3.4/site-packages/numpy/_globals.py", line 29, in <module>
raise RuntimeError('Reloading numpy._globals is not allowed')
nose.proxy.RuntimeError: Reloading numpy._globals is not allowed

# Fixed code
def reload(
    module, exclude=("sys", "os.path", builtin_mod_name, "__main__", "numpy._globals")
):
    """Recursively reload all modules used in the given module.  Optionally
    takes a list of modules to exclude from reloading.  The default exclude
    list contains sys, __main__, and __builtin__, to prevent, e.g., resetting
    display, exception, and io hooks.
    """
    global found_now
    for i in exclude:
        found_now[i] = 1
    try:
        with replace_import_hook(deep_import_hook):
            return deep_reload_hook(module)
    finally:
        found_now = {}