#1099 closed defect (fixed)
stdout might not have an 'encoding' attribute
Reported by: | davidsarah | Owned by: | zooko |
---|---|---|---|
Priority: | minor | Milestone: | 1.7.1 |
Component: | code | Version: | 1.7.0 |
Keywords: | startup encoding unicode review-needed | Cc: | |
Launchpad Bug: |
Description
Python's sys.stdout normally has an encoding attribute that specifies the name of the output encoding. We depend on this in stringutils.py.
Twisted sometimes replaces stdout with its own implementation, StdioOnnaStick. This happens (optionally) when twisted.log.startLogging is called, apparently.
As reported by Terrell Russell, this can result in the error Failed to load application: StdioOnnaStick instance has no attribute 'encoding'. when starting a Tahoe node.
I don't know why Twisted logging is started on Terrell's machine but not on any of our buildslaves or developer machines, but in any case, it is easy to change stringutils.py to not rely on the existence of sys.stdout.encoding (since we have a fallback to locale.getpreferredencoding() in that case, and to UTF-8 as a last resort).
Attachments (2)
Change History (16)
comment:1 Changed at 2010-06-25T22:42:09Z by davidsarah
Changed at 2010-06-26T04:23:02Z by davidsarah
stringutils.py: tolerate sys.stdout having no 'encoding' attribute.
comment:2 Changed at 2010-06-26T04:24:13Z by davidsarah
- Keywords test-needed review-needed added
- Owner changed from somebody to davidsarah
- Status changed from new to assigned
Terrell, please check whether applying this patch solves the problem for you.
comment:3 Changed at 2010-06-28T05:30:31Z by zooko
- Owner changed from davidsarah to terrell
- Status changed from assigned to new
comment:4 Changed at 2010-07-01T02:50:02Z by davidsarah
- Owner changed from terrell to davidsarah
- Status changed from new to assigned
Terrell reports that the problem was fixed by applying the patch and/or by upgrading Twisted to 10.0.0 (it was the stock Mac OS X install of Twisted 2.5.0).
comment:5 Changed at 2010-07-01T14:30:00Z by terrell
to be clear - each of the two solutions worked, independently - the patch, and the Twisted update.
comment:6 Changed at 2010-07-08T05:20:41Z by zooko
- Keywords reviewed added; review-needed removed
reviewed. applied in b8df25a8d1b63da1.
comment:7 Changed at 2010-07-08T05:20:48Z by zooko
- Resolution set to fixed
- Status changed from assigned to closed
comment:8 Changed at 2010-07-09T20:03:05Z by davidsarah
- Keywords regression reviewed removed
- Priority changed from major to minor
- Resolution fixed deleted
- Status changed from closed to reopened
- Summary changed from stdout might not have an 'encoding' attribute to stdout might not have an 'encoding' attribute (test needed)
This still needs a test, which would mock sys.stdout to an object that doesn't have an encoding attribute.
comment:9 Changed at 2010-07-14T07:26:35Z by zooko
http://tahoe-lafs.org/trac/tahoe-lafs/attachment/ticket/1072/rename-stringutils-drop-open_unicode.dpatch adds a test of this named test_get_output_encoding_not_from_stdout.
comment:10 Changed at 2010-07-17T04:26:11Z by davidsarah
We're not applying the #1072 patch for 1.7.1 (it's just a cleanup, it doesn't fix anything), but I will extract the test that fixes this ticket.
Changed at 2010-07-17T05:14:29Z by davidsarah
stringutils: add test for when sys.stdout has no encoding attribute (fixes #1099).
comment:11 Changed at 2010-07-17T05:14:54Z by davidsarah
- Keywords review-needed added; test-needed removed
- Owner changed from davidsarah to zooko
- Status changed from reopened to new
comment:12 Changed at 2010-07-17T07:23:28Z by zooko
- Status changed from new to assigned
comment:13 Changed at 2010-07-18T02:06:54Z by davidsarah
- Resolution set to fixed
- Status changed from assigned to closed
We ended up applying the patch for #1072 (see ticket:1072#comment:17). The test is at source:src/allmydata/test/test_encodingutil.py@4543#L87 .
comment:14 Changed at 2010-07-18T05:32:12Z by zooko
- Summary changed from stdout might not have an 'encoding' attribute (test needed) to stdout might not have an 'encoding' attribute
Twisted bug #1990 is related, but not quite the same bug. It's about StdioOnnaStick not supporting Unicode, although the print.patch there looks as though it might fix the problem. That patch has been languishing for 4 years without unit tests, though, and we'd need to work around it in Tahoe anyway.