This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: imp.frozen_init() incorrectly removes module during reload
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.4, Python 3.5
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: brett.cannon, eric.snow, ncoghlan, pje
Priority: low Keywords:

Created on 2014-03-28 18:30 by eric.snow, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (3)
msg215063 - (view) Author: Eric Snow (eric.snow) * (Python committer) Date: 2014-03-28 18:30
While reviewing code[1] for issue 20942, I noticed that when someone uses imp.frozen_init[2], the module is removed from sys.modules in some error cases.  However, this should not be done when the module already exists (e.g. reload).

As Brett pointed out in his reply to my comment in the review, frozen modules really shouldn't be reloaded, so this isn't something we necessarily need to worry about.  I.E. it's a rare corner case.  I brought it up because there's a comment in PyImport_ExecCodeModuleObject() implying a reload-related use-case.

We have 3 options:

1. don't worry about it (imp.frozen_init() is deprecated, etc.),
2. stop calling remove_module() in the reload case (i.e. be accommodating),
3. disallow reloading frozen modules (and remove that comment from import.c).

I'll shy away from #3 (consenting adults, etc.).  If someone felt like it they could work on #2, but keep in mind that there may be other reload-unfriendly code in this code path that would need adjusting if we wanted to really accommodate the use case.  I'm not convinced it's worth the trouble.

If anyone else agrees, feel free to close this issue.

[1] http://bugs.python.org/review/20942/#msg4
[2] really, anything that directly or indirectly uses PyImport_ExecCodeModuleObject() (or module_dict_for_exec() from #20942) is impacted.  In addition to imp.frozen_init(), that includes PyImport_ImportFrozenModule and PyImport_ImportFrozenModuleObject
msg215065 - (view) Author: Eric Snow (eric.snow) * (Python committer) Date: 2014-03-28 18:31
The only concrete example I can think of that would be impacted is using PJE's lazy loader on a frozen module, and even that is unlikely to trigger the error case.
msg364558 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2020-03-18 18:45
No one has cared in nearly 6 years, so I'm closing as "won't fix". :)
History
Date User Action Args
2022-04-11 14:58:00adminsetgithub: 65286
2020-03-18 18:45:46brett.cannonsetstatus: open -> closed
resolution: wont fix
messages: + msg364558

stage: test needed -> resolved
2014-03-28 18:31:57eric.snowsetnosy: + pje
messages: + msg215065
2014-03-28 18:30:43eric.snowcreate