New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
streamhandler cannot represent streams with an integer as name #80196
Comments
When debugging uwsgi logging issues with python3.7 i got this on python 3.7.2:
Traceback (most recent call last):
File "/usr/lib/python3.7/logging/__init__.py", line 269, in _after_at_fork_weak_calls
_at_fork_weak_calls('release')
File "/usr/lib/python3.7/logging/__init__.py", line 261, in _at_fork_weak_calls
method_name, "method:", err, file=sys.stderr)
File "/usr/lib/python3.7/logging/__init__.py", line 1066, in __repr__
name = name + ' '
TypeError: unsupported operand type(s) for +: 'int' and 'str' AFAICS uwsgi creates sys.stderr as an unbuffered file with PyFile_FromFd() and sets it to sys dict. |
I'm not sure this is a problem with logging. The code immediately preceding the failure is: name = getattr(self.stream, 'name', '')
if name:
name += ' ' So, the failure occurs because the stream has a name attribute which is not a string. Even if sys.stderr itself is an unbuffered file, why is its 'name' attribute not a string? I don't imagine the name would be actually used for I/O, and having it set to an integer is a surprise. I propose to close this (and the associated PR) unless a good reason is given why we have to support non-string names here. |
Yeah, I'm not sure the pr is just papering over the real issue :) Need to check what io.open sets on name. IF it setting the fd as name instead of creating a string that would be still be a bug in Python to me. Could you please wait a bit for me to check that before closing? |
In Python 3.7.2: >>> open(2, 'a')
<_io.TextIOWrapper name=2 mode='a' encoding='UTF-8'>
>>> m = _
>>> m.name
2
>>> type(_)
<class 'int'> That is, when opening a file descriptor the name is set to the value of that file descriptor as an integer. BTW. The implementation of PyFile_FromFd is a thin wrapper around the open function. |
I see. But I wonder if there is anything that relies on the name being an integer? It seems pretty counter-intuitive for a 'name' attribute to be set to something other than a string. |
Looking at Modules/_io/fileio.c::_io_FileIO___init___impl it seems an int for nameobj is just fine. Not sure I am looking at the right code though :) |
@vinay Do you have any update on this? thanks |
Sorry, Riccardo, been very busy lately and not had time to look at it :-( Soon, I hope. |
Friendly ping, would be helpful to get this resolved for 3.8.0. Thanks! |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: