pixelb / crudini

A utility for manipulating ini files
GNU General Public License v2.0
443 stars 63 forks source link

No handler for NoneType sys.stdout #82

Closed bagnaram closed 2 years ago

bagnaram commented 3 years ago

When running crudini in some GUI applications, it fails because the stdout is not set:

Traceback (most recent call last):
  File "/usr/bin/crudini", line 979, in <module>
    sys.exit(main())
  File "/usr/bin/crudini", line 975, in main
    return crudini.run()
  File "/usr/bin/crudini", line 952, in run
    sys.stdout.flush()
AttributeError: 'NoneType' object has no attribute 'flush'

https://hg.python.org/cpython/file/c9545c2386c4/Python/pythonrun.c#l1094

Suggest adding a check before checking the file descriptors:

for _name in ('stdin', 'stdout', 'stderr'):
    if getattr(sys, _name) is None:
        setattr(sys, _name, open(os.devnull, 'r' if _name == 'stdin' else 'w'))