Skip to content

bpo-33331: Clean modules in the reversed order in PyImport_Cleanup().#6565

Merged
serhiy-storchaka merged 7 commits into
python:masterfrom
serhiy-storchaka:import-cleanup-order
Oct 29, 2018
Merged

bpo-33331: Clean modules in the reversed order in PyImport_Cleanup().#6565
serhiy-storchaka merged 7 commits into
python:masterfrom
serhiy-storchaka:import-cleanup-order

Conversation

@serhiy-storchaka

@serhiy-storchaka serhiy-storchaka commented Apr 22, 2018

Copy link
Copy Markdown
Member

Modules imported last are now cleared first at interpreter shutdown.

https://bugs.python.org/issue33331

@ncoghlan ncoghlan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Due to top level modules being added to sys.modules before the modules that they import, I think this will make things worse rather than better: https://bugs.python.org/issue33331#msg319135

I've added a couple of alternative suggestions for possible improvement to the tracker issue, though.

@bedevere-bot

Copy link
Copy Markdown

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

And if you don't make the requested changes, you will be put in the comfy chair!

@serhiy-storchaka

Copy link
Copy Markdown
Member Author

I have made the requested changes; please review again.

Top level modules are now moved to the end of sys.modules, after the modules that they import.

@bedevere-bot

Copy link
Copy Markdown

Thanks for making the requested changes!

@ncoghlan, @brettcannon: please review the changes made to this pull request.

Comment thread Lib/importlib/_bootstrap.py Outdated
if spec.loader is None:
if spec.submodule_search_locations is None:
raise ImportError('missing loader', name=spec.name)
# namespace package

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Namespace package.; capitalize and end in a period (and I realize this is a hold-over from how the code already was 😄 ).

Comment thread Lib/importlib/_bootstrap.py
Comment thread Lib/importlib/_bootstrap.py
Comment thread Lib/importlib/_bootstrap.py Outdated
return sys.modules[spec.name]
# This must be done before putting the module in sys.modules
# (otherwise an optimization shortcut in import.c becomes
# wrong)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing a period.

@serhiy-storchaka

Copy link
Copy Markdown
Member Author

@ncoghlan, does the PR look good to you now?

@ncoghlan ncoghlan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I forgot I'd previously left a blocking review on this one. The move-to-the-end resolves the ordering concern I had, so this looks good to me now. Thanks!

@serhiy-storchaka
serhiy-storchaka merged commit c93c58b into python:master Oct 29, 2018
@serhiy-storchaka
serhiy-storchaka deleted the import-cleanup-order branch October 29, 2018 17:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants