Problems arising from pyinstaller and cgitb

19 views
Skip to first unread message

Jason Yu

unread,
Aug 21, 2023, 3:45:04 AM8/21/23
to PyInstaller
Hello,
I'm using python 3.8.10, and I'm using cgitb in my code.
import cgitb
path = "my path"
cgitb.enable(
display=0,
logdir=path,
context=12,
format="text"
)
If the code is abnormal, a txt file is generated.
When I compile to a separate exe file with the latest pyinstaller and use the parameter "-w", it never generates the txt file.
When I don't use the parameter "-w", it is able to produce txt files.
If I use a low version of pyinstaller, such as V4.5, even if I use the "-w" parameter, it still generates the txt file.
What does the new version of pyinstaller do? How would I fix this problem?
Looking forward to hearing from you, thanks!

bwoodsend

unread,
Aug 24, 2023, 2:21:05 AM8/24/23
to PyInstaller

Looks like cgitb is naive to windowed applications. Here it writes to a file-like attribute which gets set to sys.stdout. In a windowed application, sys.stdout is None so that line will raise some kind of NoneType has no attribute write error. The reason why it worked on older PyInstaller versions is because PyInstaller used to set sys.stdout to a placebo object with no-op .write() methods but it got scrapped because it led to other issues. You might be able to fix it by running sys.excepthook.file = open(os.devnull, "w") imediately after calling enable() or, failing that, boycott the enable() function and run this line directly but adding file = open(os.devnull, "w") to the Hook() constructor.

Reply all
Reply to author
Forward
0 new messages