You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Linecache updatecache can perform many useless os calls #140228
Consider the scenario where updatecache is called with a frozen module and module_globals is None.
In that case, _source_unavailable returns false because it is a frozen module, but because module_globals is None, the code carries on to look for the 'file' <frozen module> everywhere in sys.path. Compare that to the behavior prior to #132662 where that frozen module would simply return unavailable. I would recommend the following change:
iffilename.startswith("<frozen ") andmodule_globalsisnotNone:
# This is a frozen module, so we need to use the filename# from the module globals.fullname=module_globals.get("__file__")
iffullnameisNone:
print("fullname none")
return []
Into
iffilename.startswith("<frozen "):
ifmodule_globalsisNone:
return []
# This is a frozen module, so we need to use the filename# from the module globals.fullname=module_globals.get("__file__")
iffullnameisNone:
print("fullname none")
return []
For context, this is a problem for us because we run in a sandbox which restricts many OS operations, and this is performing useless os operations where it didn't prior to 3.14.
If there is agreement and it is helpful, happy to contribute a PR for this small change.
I would argue that type-bug is appropriate. While in most cases the impact is limited to performance, for our use case the additional filesystem calls cause a failure.
I did this PR and I agree this should be changed. Just move the comment to the start of the scope as module_globals check is related. If you want you can make a PR. Otherwise I’ll fix it myself soon.
Activity
tconley1428 commentedon Oct 17, 2025
I would argue that
type-bugis appropriate. While in most cases the impact is limited to performance, for our use case the additional filesystem calls cause a failure.gaogaotiantian commentedon Oct 18, 2025
I did this PR and I agree this should be changed. Just move the comment to the start of the scope as module_globals check is related. If you want you can make a PR. Otherwise I’ll fix it myself soon.
gh-140228: Avoid making unnecessary syscalls in linecache for frozen …
pythongh-140228: Avoid making unnecessary syscalls in linecache for f…
[3.14] gh-140228: Avoid making unnecessary syscalls in linecache for …
StanFromIreland commentedon Nov 16, 2025
Triage: Can this be closed?
gaogaotiantian commentedon Nov 16, 2025
Thank you for checking it out, closed.
pythongh-140228: Avoid making unnecessary syscalls in linecache for f…