Skip to content

streamhandler cannot represent streams with an integer as name #80196

Closed

Description

@xrmx
mannequin
BPO 36015
Nosy @vsajip, @ronaldoussoren, @xrmx
PRs
  • bpo-36015: logging: handle StreamHandler representaton of stream with int name #11908
  • [3.7] bpo-36015: Handle StreamHandler representaton of stream with an integer name (GH-11908) #13183
  • 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:

    assignee = None
    closed_at = <Date 2019-05-15.18:41:32.541>
    created_at = <Date 2019-02-17.19:20:24.118>
    labels = ['3.7', '3.8', 'type-bug', 'library']
    title = 'streamhandler cannot represent streams with an integer as name'
    updated_at = <Date 2019-05-15.18:41:32.541>
    user = 'https://github.com/xrmx'

    bugs.python.org fields:

    activity = <Date 2019-05-15.18:41:32.541>
    actor = 'vinay.sajip'
    assignee = 'none'
    closed = True
    closed_date = <Date 2019-05-15.18:41:32.541>
    closer = 'vinay.sajip'
    components = ['Library (Lib)']
    creation = <Date 2019-02-17.19:20:24.118>
    creator = 'Riccardo Magliocchetti'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 36015
    keywords = ['patch']
    message_count = 11.0
    messages = ['335784', '335814', '335819', '335822', '335843', '335868', '337207', '337362', '341766', '341832', '342590']
    nosy_count = 3.0
    nosy_names = ['vinay.sajip', 'ronaldoussoren', 'Riccardo Magliocchetti']
    pr_nums = ['11908', '13183']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue36015'
    versions = ['Python 3.7', 'Python 3.8']

    Activity

    1. xrmx commented on Feb 17, 2019

      xrmxmannequin
      MannequinAuthor
      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.

    2. added
      type-crashA hard crash of the interpreter, possibly with a core dump
      stdlibStandard Library Python modules in the Lib/ directory
      on Feb 17, 2019
    3. added
      type-bugAn unexpected behavior, bug, or error
      and removed
      type-crashA hard crash of the interpreter, possibly with a core dump
      on Feb 18, 2019
    4. vsajip commented on Feb 18, 2019

      @vsajip
      Member

      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.

    5. xrmx commented on Feb 18, 2019

      xrmxmannequin
      MannequinAuthor

      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?

    6. ronaldoussoren commented on Feb 18, 2019

      @ronaldoussoren
      Contributor

      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.

    7. vsajip commented on Feb 18, 2019

      @vsajip
      Member

      That is, when opening a file descriptor the name is set to the value of that file descriptor as an integer.

      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.

    8. changed the title [-]streamhandler canont represent streams with an integer as name[/-] [+]streamhandler cannot represent streams with an integer as name[/+] on Feb 18, 2019
    9. xrmx commented on Feb 18, 2019

      xrmxmannequin
      MannequinAuthor

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

    10. xrmx commented on Mar 5, 2019

      xrmxmannequin
      MannequinAuthor

      @vinay Do you have any update on this? thanks

    11. vsajip commented on Mar 7, 2019

      @vsajip
      Member

      Sorry, Riccardo, been very busy lately and not had time to look at it :-( Soon, I hope.

    12. xrmx commented on May 7, 2019

      xrmxmannequin
      MannequinAuthor

      Friendly ping, would be helpful to get this resolved for 3.8.0. Thanks!

    13. vsajip commented on May 7, 2019

      @vsajip
      Member

      New changeset ca87eeb by Vinay Sajip (Riccardo Magliocchetti) in branch 'master':
      bpo-36015: Handle StreamHandler representaton of stream with an integer name (GH-11908)
      ca87eeb

    14. vsajip commented on May 15, 2019

      @vsajip
      Member

      New changeset 78dd781 by Vinay Sajip (Miss Islington (bot)) in branch '3.7':
      bpo-36015: Handle StreamHandler representaton of stream with an integer name (GH-11908) (GH-13183)
      78dd781

    15. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.7 (EOL)end of life3.8 (EOL)end of lifestdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions