stdout might not have an 'encoding' attribute #1099

Closed
opened 2010-06-25 20:43:02 +00:00 by davidsarah · 11 comments
davidsarah commented 2010-06-25 20:43:02 +00:00
Owner

Python's sys.stdout normally has an encoding attribute that specifies the name of the output encoding. We depend on this in [stringutils.py]source:src/allmydata/util/stringutils.py@4491#L44.

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).

Python's `sys.stdout` normally has an `encoding` attribute that specifies the name of the output encoding. We depend on this in [stringutils.py]source:src/allmydata/util/stringutils.py@4491#L44. Twisted sometimes replaces `stdout` with its own implementation, `StdioOnnaStick`. This happens (optionally) when `twisted.log.startLogging` is called, apparently. [As reported by Terrell Russell](http://allmydata.org/pipermail/tahoe-dev/2010-June/004511.html), 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).
tahoe-lafs added the
code
major
defect
1.7.0
labels 2010-06-25 20:43:02 +00:00
tahoe-lafs added this to the 1.7.1 milestone 2010-06-25 20:43:02 +00:00
davidsarah commented 2010-06-25 22:42:09 +00:00
Author
Owner

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.

[Twisted bug #1990](http://twistedmatrix.com/trac/ticket/1990) is related, but not quite the same bug. It's about `StdioOnnaStick` not supporting Unicode, although the [print.patch](http://twistedmatrix.com/trac/attachment/ticket/1990/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.
davidsarah commented 2010-06-26 04:23:02 +00:00
Author
Owner

Attachment tolerate-no-stdout-encoding.dpatch (57007 bytes) added

stringutils.py: tolerate sys.stdout having no 'encoding' attribute.

**Attachment** tolerate-no-stdout-encoding.dpatch (57007 bytes) added stringutils.py: tolerate sys.stdout having no 'encoding' attribute.
davidsarah commented 2010-06-26 04:24:13 +00:00
Author
Owner

Terrell, please check whether applying this patch solves the problem for you.

Terrell, please check whether applying this patch solves the problem for you.
davidsarah commented 2010-07-01 02:50:02 +00:00
Author
Owner

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).

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).
terrell commented 2010-07-01 14:30:00 +00:00
Author
Owner

to be clear - each of the two solutions worked, independently - the patch, and the Twisted update.

to be clear - each of the two solutions worked, independently - the patch, and the Twisted update.

reviewed. applied in changeset:b8df25a8d1b63da1.

reviewed. applied in changeset:b8df25a8d1b63da1.
zooko added the
fixed
label 2010-07-08 05:20:48 +00:00
zooko closed this issue 2010-07-08 05:20:48 +00:00
davidsarah commented 2010-07-09 20:03:05 +00:00
Author
Owner

This still needs a test, which would mock sys.stdout to an object that doesn't have an encoding attribute.

This still needs a test, which would mock `sys.stdout` to an object that doesn't have an `encoding` attribute.
tahoe-lafs added
minor
and removed
major
fixed
labels 2010-07-09 20:03:05 +00:00
tahoe-lafs changed title from stdout might not have an 'encoding' attribute to stdout might not have an 'encoding' attribute (test needed) 2010-07-09 20:03:05 +00:00

(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.

(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`.
davidsarah commented 2010-07-17 04:26:11 +00:00
Author
Owner

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.

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.
davidsarah commented 2010-07-17 05:14:29 +00:00
Author
Owner

Attachment test-no-stdout-encoding.dpatch (5690 bytes) added

stringutils: add test for when sys.stdout has no encoding attribute (fixes #1099).

**Attachment** test-no-stdout-encoding.dpatch (5690 bytes) added stringutils: add test for when sys.stdout has no encoding attribute (fixes #1099).
davidsarah commented 2010-07-18 02:06:54 +00:00
Author
Owner

We ended up applying the patch for #1072 (see /tahoe-lafs/trac-2024-07-25/issues/6134#comment:17). The test is at source:src/allmydata/test/test_encodingutil.py@4543#L87 .

We ended up applying the patch for #1072 (see [/tahoe-lafs/trac-2024-07-25/issues/6134](/tahoe-lafs/trac-2024-07-25/issues/6134)#comment:17). The test is at source:src/allmydata/test/test_encodingutil.py@4543#L87 .
tahoe-lafs added the
fixed
label 2010-07-18 02:06:54 +00:00
zooko changed title from stdout might not have an 'encoding' attribute (test needed) to stdout might not have an 'encoding' attribute 2010-07-18 05:32:12 +00:00
Sign in to join this conversation.
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Reference: tahoe-lafs/trac-2024-07-25#1099
No description provided.