This (what i consiter a bug) plagued me for quite some time. After ALOT of searches on the topic i've found a decent solution, but i am not happy with it.
The bug is as follows;
#starts main.pyw
Import foo2.py
# foo2 contains print()
# After a few seconds(sometimes minutes) "'pythonw.exe' has stopped working."
After some research, i found out that this is due to python2 trying to force sys.stdout even know the context has no place to go. This was fixed in python3.
The program (main.pyw) is a Tkinter launcher for my game that captures the console output from foo.py. foo2.py is used by foo.py. main's console is never used, so the obvious choice was to hide it(and personally i have a small laptop, so the console was a space-hog/eye-sore)
Here is my make-shift solution:
# change 'main.pyw' to 'main.py
import ctypes
def HideConsole():
kernel32 = ctypes.Win.DLL('kernel32')
user32 = ctypes.Win.DLL('user32')
SW_HIDE = 0
hwnd = kernel32.GetConsoleWindow()
if hwnd:
user32.ShowWindow(hwnd, SW_HIDE)
HideConsole()
This works fine. Python.exe starts, the console opens, the console closes, then Tkinter starts, and the crashes are stopped. But i am getting the feeling that this isn't the right solution, what are your thoughts? Is there a better way to hide the console without using pythonw?
Edit: I have tried redirecting sys.stdout, and also the Print()'s are important to another script, so i'd rather not touch them.