-
Notifications
You must be signed in to change notification settings - Fork 145
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
Do our best to ensure we don't add the same handler more than once. #101
Conversation
Previously, constructing a new GCM(debug=True) twice would result in two debug handlers being added.
If you provide your own Perhaps the current handler, regardless if provided by the client or created here, could be stored, and then there could be a |
That's why I call removeHandler, so that if you provide the same handler twice, it won't be double-added. If you call enable_logging with two separate handlers, it would make sense to me that both handlers would be added. Though yes, this API wasn't well-designed, especially in combination with a GCM(debug=True) case that leads one to think logging is isolated to the new GCM (when in fact, it is global). I did extra work to improve enable_logging() as well, for those who might call it with a custom handler. But if you have a preference for me to implement a disable_logging/reset_logging implementation instead, to get this submitted, I can do that instead. |
@mikelambert I added the logging API only for python-gcm internal development purposes, to make it easier to see what's going on under the hood. Thanks for making this pull request, I think it is fine with the changes you've made, but as per CONTRIBUTING.md can you please do the following two things:
|
@mikelambert I've updated my explanation above. Can you also provide a use case where you needed to create more than one GCM object? |
I'm calling GCM from AppEngine, and so creating and using a GCM object as part of fulfilling the request. I didn't see anything about thread-safety in the code, and I generally avoid using complex shared module-level objects due to concurrency fears. But it sounds like from your above comment that these objects are thread-safe, and I can just re-use the GCM object. If so, that works for me. Though I might suggest comments/docstrings in the code/readme discussing the threadsafe nature of these objects, and the internal-only-ness of the debug= parameter. (I needed it when trying to diagnose why my GCM calls weren't working, but that was due to requests-on-appengine being broken, which I've got another set of pull requests out to fix. You're right that in the steady-state case, I don't actually need GCM debugging at all.) |
@mikelambert Thanks for the PR. I took the commit you've made and added it to the develop branch myself and as the code coverage has not decreased it is okay even without a test. |
Previously, constructing a new GCM(debug=True) twice would result in two debug handlers being added.