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

Question Regarding Global Statements #154

Open
Keydex opened this issue Feb 7, 2021 · 0 comments
Open

Question Regarding Global Statements #154

Keydex opened this issue Feb 7, 2021 · 0 comments

Comments

@Keydex
Copy link

Keydex commented Feb 7, 2021

Hello!

I wanted to read more on the references on this page https://docs.quantifiedcode.com/python-anti-patterns/maintainability/using_the_global_statement.html

I know the book entails things you should "NEVER" do in practice. So I ask this in the context of putting things in the global scope.

Do we consider instantiating built in modules like logger anti patterns? Or should this be something that should be encapsulated in its own class.

import logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

Or perhaps this was meant to deter a developer from using the global statement.

The logging function is something I want to instantiate on any files that logs and it seems safe if I define it everywhere.
The logging module is intended to be thread-safe without any special work needing to be done by its clients. It achieves this though using threading locks; there is one lock to serialize access to the module’s shared data, and each handler also creates a lock to serialize access to its underlying I/O.
https://docs.python.org/3/library/logging.html#thread-safety

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant