-
Notifications
You must be signed in to change notification settings - Fork 19
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
add Context manager and default context under threading #38
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this! Some comments below.
Fix future warning date of DEFAULT_CONTEXT Co-authored-by: Andreas Klöckner <inform@tiker.net>
I have put |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! A few more minor things, then this is ready to go.
.. note:: this class implements Python's ``__copy__`` and ``__deepcopy__`` | ||
protocals. Copying of objects of this class always returns the identity. | ||
|
||
.. seealso:: :ref:`sec-context-management` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a note on pickle
behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
However, I'm thinking towards a slightly better semantics of pickling of Context. I can't imagine a use case for this, but here's a sketch:
@functools.lru_cache(maxsize=None)
def _get_context_by_id(ctx_id):
return Context()
def context_reduce(self):
if self == get_default_context():
return (get_default_context, ())
return (_get_context_by_id, (hash(self), ))
What do you think?
islpy/__init__.py
Outdated
return get_default_context() | ||
|
||
|
||
import contextlib |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move to top of file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Co-authored-by: Andreas Klöckner <inform@tiker.net>
Co-authored-by: Andreas Klöckner <inform@tiker.net>
Co-authored-by: Andreas Klöckner <inform@tiker.net>
Co-authored-by: Andreas Klöckner <inform@tiker.net>
…am/islpy into default_context_managing
Please have proper commit messages. |
(OK to leave these, just for the future.) |
Sorry, I believe they were generated automatically by GitHub. I will definitely note this in the future. |
They are, but you have the option to change them when you click "Commit". |
This implements #22
Semantics of context pushing is added as a test case.
With this change:
DEFAULT_CONTEXT
is deprecated (with a warning) in favor ofget_default_context()
get_default_context()
always returns a thread unique default context for the first call in a thread.push_context(ctx=none)
can be used to push new default context(s), which allows for custom default Context.__copy__
and__deepcopy__
which always returns the identity.