Uploaded image for project: 'Picard'
  1. Picard
  2. PICARD-2688

Windows: Portable version crashes when launched with "-h"

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Low Low
    • 2.9.1
    • None
    • Packaging & Deployment
    • None

      E.g. when I run "MusicBrainz-Picard-2.9.0b3.exe -h" the mouse pointer first briefly changes to a loading animation and then an error dialog appears:

      Failed to execute script 'tagger' due to unhandled exception:
      'NoneType' object has no attribute 'write'
      
      Traceback (most recent call last):
        File "tagger.py", line 17, in <module>
        File "tagger.py", line 1440, in main
        File "tagger.py", line 1398, in process_picard_args
        File "argparse.py", line 1768, in parse_args
        File "argparse.py", line 1800, in parse_known_args
        File "argparse.py", line 2006, in _parse_known_args
        File "argparse.py", line 1946, in consume_optional
        File "argparse.py", line 1874, in take_action
        File "argparse.py", line 1044, in __call__
        File "argparse.py", line 2494, in print_help
        File "argparse.py", line 2500, in _print_message
      AttributeError: 'NoneType' object has no attribute 'write'
      

      However if use an option that opens the GUI there is no error (but no command line output either for e.g. "-d")

          [PICARD-2688] Windows: Portable version crashes when launched with "-h"

          GitHub Bot added a comment -

          See code changes in pull request #2259 submitted by phw.

          GitHub Bot added a comment - See code changes in pull request #2259 submitted by phw .

          We can probably avoid raising that exceptions, but we likely can't do anything about the missing output.

          In general Windows strictly distinguishes between GUI and CLI applications. Essentially GUI applications can create Windows, but they don't have a console attached. CLI applications have a console attached, but can't create Windows.

          That means naturally that when starting a GUI application from console you won't see any output there. For the normal installer package of Picard we do some shenanigans to allow console output anyway (https://github.com/metabrainz/picard/blob/master/scripts/pyinstaller/win-startup-hook.py#L28-L34). This way launching Picard on Windows from a console works very similar to other platforms. Not entirely, though, as e.g. the console does not block while Picard is running. Windows still detaches the launched application from the console, but we trick it into writing output to the console anyway.

          For some reason this does not work for the onefile package. I investigated this a bit when I implemented the console workaround. I don't know the exact reason, but it seems to be related to how launching the application works in the onefile case, where it first has to extract all the files into a temporary folder before actually launching the application itself.

          Philipp Wolfer added a comment - We can probably avoid raising that exceptions, but we likely can't do anything about the missing output. In general Windows strictly distinguishes between GUI and CLI applications. Essentially GUI applications can create Windows, but they don't have a console attached. CLI applications have a console attached, but can't create Windows. That means naturally that when starting a GUI application from console you won't see any output there. For the normal installer package of Picard we do some shenanigans to allow console output anyway ( https://github.com/metabrainz/picard/blob/master/scripts/pyinstaller/win-startup-hook.py#L28-L34). This way launching Picard on Windows from a console works very similar to other platforms. Not entirely, though, as e.g. the console does not block while Picard is running. Windows still detaches the launched application from the console, but we trick it into writing output to the console anyway. For some reason this does not work for the onefile package. I investigated this a bit when I implemented the console workaround. I don't know the exact reason, but it seems to be related to how launching the application works in the onefile case, where it first has to extract all the files into a temporary folder before actually launching the application itself.

          Zas added a comment -

          Zas added a comment - It looks like similar to https://github.com/microsoft/playwright-python/issues/1148 Basically sys.stderr = None in the reported case. https://github.com/python/cpython/blob/06f8a439956fdf5f2d68bc3b5b6e2499981ce21f/Lib/argparse.py#L2605-L2607 That's related to pyinstaller options used to build the package -> https://pyinstaller.org/en/stable/usage.html#windows-and-mac-os-x-specific-options

          chaban added a comment -

          Maybe "doesn't process" isn't quite correct. "-e load URL" for example works for me.

          chaban added a comment - Maybe "doesn't process" isn't quite correct. "-e load URL" for example works for me.

            outsidecontext Philipp Wolfer
            chaban chaban
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:

                Version Package
                2.9.1