Skip to content

Autoreload error when running a script #8564

@jewfro-cuban

Description

@jewfro-cuban

When running a script I get an error:

Error in callback <bound method AutoreloadMagics.post_execute_hook of <autoreload.AutoreloadMagics object at 0x00000000045E1B70>> (for post_execute):
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
C:\<path_to_env>\lib\site-packages\IPython\extensions\autoreload.py in post_execute_hook(self)
    523         newly_loaded_modules = set(sys.modules) - self.loaded_modules
    524         for modname in newly_loaded_modules:
--> 525             _, pymtime = self._reloader.filename_and_mtime(sys.modules[modname])
    526             if pymtime is not None:
    527                 self._reloader.modules_mtimes[modname] = pymtime

C:\<path_to_env>\lib\site-packages\IPython\extensions\autoreload.py in filename_and_mtime(self, module)
    188
    189         # if hasattr(module, '__name__'):
--> 190         if module.__name__ == '__main__':
    191             # we cannot reload(__main__)
    192             return None, None

AttributeError: 'module' object has no attribute '__name__'

I've fixed it locally with:

        if hasattr(module, '__name__'):
            if module.__name__ == '__main__':
                # we cannot reload(__main__)
                return None, None

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions