After the last line (print statement) in my python code, I get the following error:
close failed in file object destructor:
sys.excepthook is missing
lost sys.stderr
Anyone know where this might be coming from?
Update: My python code is extremely long but I will post portions that may have something to do with this error:
For one, near the beginning of the process I redirect stdout and stderr to a log file like this:
so = se = open(logfile, 'w', 0)
sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
os.dup2(so.fileno(), sys.stdout.fileno())
os.dup2(se.fileno(), sys.stderr.fileno())
I do this all the time though and have never run into this error but it seems the most likely reason I'm seeing this.
Adding the following statement to the very end of my main function fixes this issue for me:
try:
sys.stdout.close()
except:
pass
try:
sys.stderr.close()
except:
pass
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With