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

python 3.12->3.13's logging.Handler requres .createLock() et.al., and possibly .lock #125606

Closed
cagney opened this issue Oct 16, 2024 · 2 comments
Labels
type-bug An unexpected behavior, bug, or error

Comments

@cagney
Copy link

cagney commented Oct 16, 2024

Bug report

Bug description:

This code block was working in 3.12 but barfs in 3.13

class DebugHandler(logging.Handler):

    def __init__(self):
        logging.Handler.__init__(self)
        self.stream_handlers = list()
        self.setLevel(NONE)
        self.setFormatter(_DEBUG_FORMATTER)

    def emit(self, record):
        for stream_handler in self.stream_handlers:
            stream_handler.emit(record)
        if _DEBUG_STREAM:
            _DEBUG_STREAM.emit(record)

    def push(self, stream):
        stream_handler = logging.StreamHandler(stream)
        stream_handler.setFormatter(_DEBUG_FORMATTER)
        self.stream_handlers.append(stream_handler)
        self.setLevel(DEBUG)

    def pop(self):
        stream_handler = self.stream_handlers.pop()
        stream_handler.flush()
        # This doesn't close the file; and probably does nothing.
        stream_handler.close()
        if not self.stream_handlers:
            self.setLevel(NONE)

    def flush(self):
        for stream_handler in self.stream_handlers:
            stream_handler.flush()

because my class doesn't provide:

    def createLock(self):
        pass
    def acquire(self):
        pass
    def release(self):
        pass

is needing to add these function's considered a regression?

This leads to my second problem, I'm not clear on how these should be implemented. With the above code I get:

File "/usr/lib64/python3.13/logging/init.py", line 1664, in _log
self.handle(record)
~~~~~~~~~~~^^^^^^^^
File "/usr/lib64/python3.13/logging/init.py", line 1680, in handle
self.callHandlers(record)
~~~~~~~~~~~~~~~~~^^^^^^^^
File "/usr/lib64/python3.13/logging/init.py", line 1736, in callHandlers
hdlr.handle(record)
~~~~~~~~~~~^^^^^^^^
File "/usr/lib64/python3.13/logging/init.py", line 1025, in handle
with self.lock:
^^^^^^^^^
AttributeError: 'DebugHandler' object has no attribute 'lock'

According to the docs, NullHandler has https://docs.python.org/3/library/logging.handlers.html#nullhandler

createLock()
    This method returns None for the lock, since there is no underlying I/O to which access needs to be serialized.

but when I look at the code I find:

    def createLock(self):
        self.lock = None

I guess I try extending NullHandler()

CPython versions tested on:

3.13

Operating systems tested on:

Linux

@cagney cagney added the type-bug An unexpected behavior, bug, or error label Oct 16, 2024
@cagney cagney changed the title python 3.13->3.13's logging.Handler requres .createLock() et.al., and possibly .lock python 3.12->3.13's logging.Handler requres .createLock() et.al., and possibly .lock Oct 16, 2024
@cagney
Copy link
Author

cagney commented Oct 16, 2024

Sorry, looks like wrong information passed to me.

@cagney cagney closed this as completed Oct 16, 2024
@cagney
Copy link
Author

cagney commented Oct 16, 2024

createLock() was added as a work-around for https://bugs.python.org/issue6721#msg329474
the documentation on how to implement it in NullHandler is wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant