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

PixivUtil2 Crashes When Output is Piped #1065

Closed
SeanZWrites opened this issue Dec 20, 2021 · 1 comment · Fixed by #1082
Closed

PixivUtil2 Crashes When Output is Piped #1065

SeanZWrites opened this issue Dec 20, 2021 · 1 comment · Fixed by #1082

Comments

@SeanZWrites
Copy link

Prerequisites

  • [ x ] Did you read FAQ section in readme.md?
  • [ x ] Did you test with the latest releases or commit ?
  • [ x ] Did you search for existing issues in Issues?

Description

When using PixivUtil2, and the output is piped or tee-d in the shell, the program crashes with the following traceback:

Traceback (most recent call last):
  File "PixivUtil2.py", line 1496, in <module>
    main()
  File "PixivUtil2.py", line 1289, in main
    set_console_title()
  File "PixivUtil2.py", line 989, in set_console_title
    PixivHelper.set_console_title(set_title)
  File "/home/USER/PixivUtil2/PixivHelper.py", line 380, in set_console_title
    sys.stdout.write(f'\33]0;{title}\a')
  File "/home/USER/PixivUtil2/venv/lib/python3.8/site-packages/colorama/ansitowin32.py", line 41, in write
    self.__convertor.write(text)
  File "/home/USER/PixivUtil2/venv/lib/python3.8/site-packages/colorama/ansitowin32.py", line 162, in write
    self.write_and_convert(text)
  File "/home/USER/PixivUtil2/venv/lib/python3.8/site-packages/colorama/ansitowin32.py", line 184, in write_and_convert
    text = self.convert_osc(text)
  File "/home/USER/PixivUtil2/venv/lib/python3.8/site-packages/colorama/ansitowin32.py", line 257, in convert_osc
    winterm.set_title(params[1])
AttributeError: 'NoneType' object has no attribute 'set_title'

This appears to be due to trying to set the terminal window title when piped. If we modify the set_console_title function like this, it works fine:

def set_console_title(title=''):
    try: 
        set_title = f'PixivDownloader {PixivConstant.PIXIVUTIL_VERSION} {title}'
        PixivHelper.set_console_title(set_title)
    except: 
        pass

Steps to Reproduce

  1. Pipe the output to another process or tee it: python PixivUtil2.py --help | tee log.txt

Expected behavior: The code should run normally.

Actual behavior: The application crashes.

Log file: Log is blank.

Versions

PixivDownloader2 version 20211104

@dragontamer8740
Copy link
Contributor

This did not fix the issue.

Traceback (most recent call last):
  File "/home/fake-user-name/bin/PixivUtil2", line 1566, in <module>
    main()
  File "/home/fake-user-name/bin/PixivUtil2", line 1359, in main
    set_console_title()
  File "/home/fake-user-name/bin/PixivUtil2", line 1044, in set_console_title
    PixivHelper.set_console_title(set_title)
  File "/home/fake-user-name/development/PixivUtil2/PixivHelper.py", line 389, in set_console_title
    sys.stdout.write(f'\33]0;{title}\a')
  File "/usr/lib/python3/dist-packages/colorama/ansitowin32.py", line 41, in write
    self.__convertor.write(text)
  File "/usr/lib/python3/dist-packages/colorama/ansitowin32.py", line 162, in write
    self.write_and_convert(text)
  File "/usr/lib/python3/dist-packages/colorama/ansitowin32.py", line 184, in write_and_convert
    text = self.convert_osc(text)
  File "/usr/lib/python3/dist-packages/colorama/ansitowin32.py", line 256, in convert_osc
    winterm.set_title(params[1])
AttributeError: 'NoneType' object has no attribute 'set_title'

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 a pull request may close this issue.

2 participants