Skip to content

Commit

Permalink
Fix encoding error for logging crashes with non-ascii characters
Browse files Browse the repository at this point in the history
  • Loading branch information
totycro committed Nov 27, 2011
1 parent 322b3ab commit 6678111
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion run_uh.py
Expand Up @@ -276,7 +276,11 @@ class StdOutDuplicator(object):
def write(self, line):
line = unicode(line)
sys.__stdout__.write(line)
logfile.write(line)
try:
logfile.write(line)
except UnicodeEncodeError:
# python unicode handling is weird, this has been empirically proven to work
logfile.write( line.encode("UTF-8") )
sys.stdout = StdOutDuplicator()

# add a handler to stderr too _but_ only if logfile isn't already a tty
Expand Down

0 comments on commit 6678111

Please sign in to comment.