Skip to content
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

Error when debugging logging.FileHandler subclass __init__ method #86285

Closed
fcodvpt mannequin opened this issue Oct 22, 2020 · 3 comments
Closed

Error when debugging logging.FileHandler subclass __init__ method #86285

fcodvpt mannequin opened this issue Oct 22, 2020 · 3 comments
Labels
3.8 only security fixes 3.9 only security fixes 3.10 only security fixes 3.11 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@fcodvpt
Copy link
Mannequin

fcodvpt mannequin commented Oct 22, 2020

BPO 42119
Nosy @Fidget-Spinner, @fcodvpt, @akulakov
Superseder
  • bpo-20853: pdb "args" crashes when an arg is not printable
  • Files
  • multiprocesses-to-files-with-dict.py: Code with the FileHandler subclass
  • 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 2021-09-10.15:05:22.816>
    created_at = <Date 2020-10-22.16:37:47.672>
    labels = ['3.8', '3.9', '3.10', '3.11', 'type-feature', 'library']
    title = 'Error when debugging logging.FileHandler subclass __init__ method'
    updated_at = <Date 2021-09-12.15:06:19.517>
    user = 'https://github.com/fcodvpt'

    bugs.python.org fields:

    activity = <Date 2021-09-12.15:06:19.517>
    actor = 'andrei.avk'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-09-10.15:05:22.816>
    closer = 'andrei.avk'
    components = ['Library (Lib)']
    creation = <Date 2020-10-22.16:37:47.672>
    creator = 'fcodvpt'
    dependencies = []
    files = ['49535']
    hgrepos = []
    issue_num = 42119
    keywords = []
    message_count = 3.0
    messages = ['379313', '398452', '401668']
    nosy_count = 3.0
    nosy_names = ['kj', 'fcodvpt', 'andrei.avk']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'resolved'
    status = 'closed'
    superseder = '20853'
    type = 'enhancement'
    url = 'https://bugs.python.org/issue42119'
    versions = ['Python 3.8', 'Python 3.9', 'Python 3.10', 'Python 3.11']

    @fcodvpt
    Copy link
    Mannequin Author

    fcodvpt mannequin commented Oct 22, 2020

    In pdb, when I hit "a" to see __init__ parameters of a logging.FileHandler subclass, I get an error because __repr__ needs a logging level. The level has been removed from the parameters by configure_handler() when it instanciates the handler. The level is set after the handler instanciation.

    I do not know if it can be changed or if I missed something.

    Traceback (most recent call last):
      File "/usr/lib/python3.8/logging/config.py", line 563, in configure
        handler = self.configure_handler(handlers[name])
      File "/usr/lib/python3.8/logging/config.py", line 744, in configure_handler
        result = factory(**kwargs)
      File "/home/fconil/Progs/python/logging/multiprocesses-to-files-with-dict.py", line 53, in __init__
        pfilename = f"{filename}-{os.getpid()}.log"
      File "/home/fconil/Progs/python/logging/multiprocesses-to-files-with-dict.py", line 53, in __init__
        pfilename = f"{filename}-{os.getpid()}.log"
      File "/usr/lib/python3.8/bdb.py", line 88, in trace_dispatch
        return self.dispatch_line(frame)
      File "/usr/lib/python3.8/bdb.py", line 112, in dispatch_line
        self.user_line(frame)
      File "/usr/lib/python3.8/pdb.py", line 262, in user_line
        self.interaction(frame, None)
      File "/usr/lib/python3.8/pdb.py", line 357, in interaction
        self._cmdloop()
      File "/usr/lib/python3.8/pdb.py", line 322, in _cmdloop
        self.cmdloop()
      File "/usr/lib/python3.8/cmd.py", line 138, in cmdloop
        stop = self.onecmd(line)
      File "/usr/lib/python3.8/pdb.py", line 423, in onecmd
        return cmd.Cmd.onecmd(self, line)
      File "/usr/lib/python3.8/cmd.py", line 217, in onecmd
        return func(arg)
      File "/usr/lib/python3.8/pdb.py", line 1146, in do_args
        self.message('%s = %r' % (name, dict[name]))
      File "/usr/lib/python3.8/logging/__init__.py", line 1186, in __repr__
        level = getLevelName(self.level)
    AttributeError: 'MultiFileHandler' object has no attribute 'level'

    @fcodvpt fcodvpt mannequin added 3.8 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels Oct 22, 2020
    @akulakov
    Copy link
    Contributor

    Françoise:

    You can simply set the two attrs required by __repr__ in the pdb session:

    ./python.exe ~/temp/a.py --INS--

    /Users/ak/opensource/cpython/Lib/logging/init.py(1152)init()
    -> filename = os.fspath(filename)
    (Pdb) self.level=1
    (Pdb) self.baseFilename='test.log'
    (Pdb) a
    self = <FileHandler test.log (Level 1)>
    filename = 'test.log'
    mode = 'a'
    encoding = None
    delay = False
    errors = None
    (Pdb)

    I think this can be closed as it's not a bug and there's a workaround as shown above.

    @akulakov akulakov added 3.9 only security fixes 3.10 only security fixes 3.11 only security fixes labels Jul 29, 2021
    @akulakov
    Copy link
    Contributor

    Changing from not a bug to duplicate of bpo-20853.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.8 only security fixes 3.9 only security fixes 3.10 only security fixes 3.11 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant