haypo/faulthandler — Issue #3: Support for redirected streams
Author: alberthrocks
Created: 2011-12-20 04:22:05+00:00
State: open

My program redirects stdout and stderr streams to a log file. However, the module refuses to dump a trace because the "fileno" isn't inside my custom class. I tried implementing it (and as accurately as I can - not a dummy function - I return the log file's FD), but nothing gets written to the log file.

I am attempting to dump a trace _without_ a crash - that is, when something hangs.

Some other info:
- faulthandler is called inside another thread
- OS: Windows Vista
- Python version: 2.7 x86
- Faulthandler version: 2.0 (Pipi repo)
- Code used:
==============================
class LogWriter:
def __init__(self, filename):
self.logfile = file(filename, 'a')
self.logfile.write("** Log Session Start - "+date("%Y-%m-%d %H:%M:%S")+" **\n")
self.enabledate = False
def write(self, text):
if self.enabledate == True:
if text.strip() != "":
self.logfile.write("["+date("%Y-%m-%d %H:%M:%S")+"] "+text.rstrip()+"\n")
else:
self.logfile.write(text)
self.logfile.flush()
def close(self):
self.logfile.write("** Log Session End - "+date("%Y-%m-%d %H:%M:%S")+" **\n")
self.logfile.close()
def fileno(self):
return self.logfile.fileno()

def start():
"""Displays the GUI and starts the GUI Loop"""
# Set up the debug logging
DEBUGGING = 1
if DEBUGGING == 1:
global logout
logout = LogWriter("croquette_log.txt")
oldstdout = sys.stdout
sys.stdout = logout
oldstderr = sys.stderr
sys.stderr = logout

============================

Thanks!