[Python-Dev] Timeout for PEP 550 (original) (raw)
[Python-Dev] Timeout for PEP 550 / Execution Context discussion
Nick Coghlan ncoghlan at gmail.com
Tue Oct 17 01:12:46 EDT 2017
- Previous message (by thread): [Python-Dev] Timeout for PEP 550 / Execution Context discussion
- Next message (by thread): [Python-Dev] Timeout for PEP 550 / Execution Context discussion
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 17 October 2017 at 15:02, Nick Coghlan <ncoghlan at gmail.com> wrote:
On 17 October 2017 at 14:31, Guido van Rossum <guido at python.org> wrote:
No, that version just defers to magic in ContextVar.get/set, whereas what I'd like to see is that the latter are just implemented in terms of manipulating the mapping directly. The only operations for which speed matters would be getitem and setitem; most other methods just defer to those. delitem must also be a primitive, as must iter and len -- but those don't need to be as speedy (however delitem must really work!).
To have the mapping API at the base of the design, we'd want to go back to using the ContextKey version of the API as the core primitive (to ensure we don't get name conflicts between different modules and packages), and then have ContextVar be a convenience wrapper that always accesses the currently active context: class ContextKey: ... class ExecutionContext: ... class ContextVar: def init(self, name): self.key = ContextKey(name) def get(self): return getexecutioncontext()[self.key] def set(self, value): getexecutioncontext()[self.key] = value def delete(self, value): del getexecutioncontext()[self.key]
Tangent: if we do go this way, it actually maps pretty nicely to the idea of a "threading.ThreadVar" API that wraps threading.local():
class ThreadVar:
def __init__(self, name):
self._name = name
self._storage = threading.local()
def get(self):
return self._storage.value
def set(self, value):
self._storage.value = value
def delete(self):
del self._storage.value
(Note: real implementations of either idea would need to pay more attention to producing clear exception messages and instance representations)
Cheers, Nick.
-- Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20171017/9a637f40/attachment.html>
- Previous message (by thread): [Python-Dev] Timeout for PEP 550 / Execution Context discussion
- Next message (by thread): [Python-Dev] Timeout for PEP 550 / Execution Context discussion
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]