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

logging.handlers.QueueListener sentinel should not be None #60875

Closed
AndrasSzalai mannequin opened this issue Dec 12, 2012 · 4 comments
Closed

logging.handlers.QueueListener sentinel should not be None #60875

AndrasSzalai mannequin opened this issue Dec 12, 2012 · 4 comments
Assignees
Labels
type-bug An unexpected behavior, bug, or error

Comments

@AndrasSzalai
Copy link
Mannequin

AndrasSzalai mannequin commented Dec 12, 2012

BPO 16671
Nosy @vsajip

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 = 'https://github.com/vsajip'
closed_at = <Date 2012-12-13.09:26:07.578>
created_at = <Date 2012-12-12.18:28:09.618>
labels = ['type-bug', 'invalid']
title = 'logging.handlers.QueueListener sentinel should not be None'
updated_at = <Date 2012-12-13.09:26:07.577>
user = 'https://bugs.python.org/AndrasSzalai'

bugs.python.org fields:

activity = <Date 2012-12-13.09:26:07.577>
actor = 'vinay.sajip'
assignee = 'vinay.sajip'
closed = True
closed_date = <Date 2012-12-13.09:26:07.578>
closer = 'vinay.sajip'
components = []
creation = <Date 2012-12-12.18:28:09.618>
creator = 'Andras.Szalai'
dependencies = []
files = []
hgrepos = []
issue_num = 16671
keywords = []
message_count = 4.0
messages = ['177385', '177395', '177400', '177401']
nosy_count = 2.0
nosy_names = ['vinay.sajip', 'Andras.Szalai']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = None
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue16671'
versions = ['Python 3.2', 'Python 3.3', 'Python 3.4', 'Python 3.5']

@AndrasSzalai
Copy link
Mannequin Author

AndrasSzalai mannequin commented Dec 12, 2012

In the class logging.handlers.QueueListener the _sentinel is None.

But
>>> a = None
>>> b = None
>>> a is b
True

Because of this, the QueueListener stops if it receives a None.
Were the sentinel a proper instance, like:
_sentinel = {}

This would not happen.

@AndrasSzalai AndrasSzalai mannequin added the type-bug An unexpected behavior, bug, or error label Dec 12, 2012
@vsajip
Copy link
Member

vsajip commented Dec 13, 2012

Why do you think None is a valid value to send for normal operation? Since the queue is only meant for sending logging events (records), it seems reasonable to send None as a sentinel - it should never be seen during operation.

The QueueListener is *supposed* to stop if it sees a None, so don't send those over the queue - just send logging events - until you want to shut the listener down.

You can of course set the sentinel to whatever you want, in your own code, and then send that. The default value of None seems OK to me.

So I don't believe this is a valid issue - marking as such and as pending, and I will close this shortly unless you come back with some more information.

@vsajip vsajip added the invalid label Dec 13, 2012
@vsajip vsajip self-assigned this Dec 13, 2012
@AndrasSzalai
Copy link
Mannequin Author

AndrasSzalai mannequin commented Dec 13, 2012

What mislead me is:

The current code uses is and opposed to == which I assume is for the very specific reason to match identity and not value.

The sentinel starts with a _, which to a casual reader (me) suggests that it's a private implementation detail that I should not have to touch. (am I right on this?)

http://plumberjack.blogspot.co.uk/2010/09/improved-queuehandler-queuelistener.html

In the introduction of this very same class you are also mentioning that:

"... QueueListener is not even especially logging-specific: You can pass it as a handler any object that has a handle method which takes a single argument, and that method will be passed any non-sentinel object which appears on the queue."

also

"You should be able to paste QueueHandler and QueueListener into your own code..."

So suddenly logging in not the only documented use case.

And yes, I can override the sentinel in my subclass, yet it is named as _sentinel, which again suggests "do not touch" to me.

It's a tiny inconsistency that may never come up again for anyone else, but I just used a copy of the class and it came up for me. My tests caught it, I fixed it up for my own use-case, case closed.

So honestly it's not the end of the world, but neither is changing it to a safer default, like {} or even self.

I won't be bothering you with this issue anymore, so feel free to close it if you want.

@vsajip
Copy link
Member

vsajip commented Dec 13, 2012

The sentinel starts with a _, which to a casual reader (me) suggests
that it's a private implementation detail that I should not have to
touch. (am I right on this?)

Python is a language for consenting adults, so nothing is off-limits, except that you need to know what you are doing when you make changes to internal attributes, and may not get support from the original author if something breaks. However, notice that I set it up as a class value which could be overridden at an instance level, rather than hard-coding None into the sentinel test. So, it *was* intended to be changed if needed, but it's more appropriate for a subclass to do that than a user of the class (not that a user is *forbidden* - that couldn't be enforced, anyway).

@vsajip vsajip closed this as completed Dec 13, 2012
@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
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant