Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

loader: disable import tracing if sys.stderr is unavailable #5477

Merged
merged 1 commit into from Jan 28, 2021

Conversation

rokm
Copy link
Member

@rokm rokm commented Jan 17, 2021

The FrozenImporter in pymod03_importers uses trace() function if sys.flags.verbose is enabled to trace the imports to sys.stderr. This results in the following error:
Failed to execute script pyiboot01_bootstrap
when sys.stderr is unavailable (is None), which happens on Windows when windowed bootloader is used in combination with
sys.flags.verbose enabled (i.e., --debug imports or --debug all is passed on the command-line).

The problem is that while pyiboot01_bootstrap does install its NullWriter for sys.stderr when the latter is unavailable, that
happens too late; there is an import os that happens between the end of bootstrap process (the pyimod03_importers.install() call) and monkey-patching NullWriter() into sys.stderr.

While the problem could also be fixed by moving the NullWriter initialization before the offending import, simply disabling the trace() function seems a better option.

Fixes #4213.

The `FrozenImporter` in `pymod03_importers` uses `trace()` function
if `sys.flags.verbose` is enabled to trace the imports to `sys.stderr`.
This results in the following error:
  `Failed to execute script pyiboot01_bootstrap`
when `sys.stderr` is unavailable (is `None`), which happens on
Windows when windowed bootloader is used in combination with
`sys.flags.verbose` enabled (i.e., `--debug imports` or
`--debug all` is passed on the command-line).

The problem is that while `pyiboot01_bootstrap` does install its
`NullWriter` for `sys.stderr` when the latter is unavailable, that
happens too late; there is an `import os` that happens between the
end of bootstrap process (the `pyimod03_importers.install()` call)
and monkey-patching `NullWriter()` into `sys.stderr`.

While the problem could also be fixed by moving the `NullWriter`
initialization before the offending import, simply disabling the
`trace()` function seems a better option.

Fixes pyinstaller#4213.
@rokm rokm marked this pull request as ready for review January 18, 2021 11:32
@Legorooj Legorooj merged commit f74d7dd into pyinstaller:develop Jan 28, 2021
@FabioDavidF
Copy link

Thank you so much! This fix saved me

@rokm rokm deleted the fix-4213 branch January 28, 2021 17:57
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Program fails at pyiboot01_bootstrap when using --noconsole
4 participants