-
Notifications
You must be signed in to change notification settings - Fork 1
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
How about using a context manager? #1
Comments
No matter how it would look like, I'm sure that we need to any way to manage contexts. The current logging-spinner has nothing about this at all. One thing making me to consider is that logging-spinner's first purpose is to display spinners without introducing any third-party APIs. Applications don't have to depend on logging-spinner's own API, but a loose protocol of the Actually logging-spinner uses pyspin under the hood. Although it doesn't provide context managers, there's |
I don't see any third party API introduction here. It is just a simple context manager, you can provide him additionally:
The whole purpose of context manager in python is to manage resources. Everything that has some kind of open-close or start-end procedures is suited perfect for this. Opening and automatically closing files, connect and disconnect to databases, creating and deleting of tmp files and dictionaries etc. Creating takes one or two minutes, why not provide it from the beginning? By the way controlling the spinner is also not that hard:
The with statement or also called context manager is considered as very safe, clean and therefore pythonic! |
Implementing a spinner through a context manager would provide a even better interface. Something like this for example:
So you could provide even more complex behaivor like stopping the spinner or change color or whatever.
For a simple spinner you could also provide this:
It is just a suggestion, because I really like the context manager interface, keeps the code cleaner and so on ;)
The text was updated successfully, but these errors were encountered: