[Python-Dev] PEP 567 v2 (original) (raw)

Yury Selivanov yselivanov.ml at gmail.com
Thu Dec 28 10:36:37 EST 2017


On Thu, Dec 28, 2017 at 5:28 AM, Chris Jerdonek <chris.jerdonek at gmail.com> wrote:

I have a couple basic questions around how this API could be used in practice. Both of my questions are for the Python API as applied to Tasks in asyncio.

1) Would this API support looking up the value of a context variable for another Task? For example, if you're managing multiple tasks using asyncio.wait() and there is an exception in some task, you might want to examine and report the value of a context variable for that task.

No, unless that another Task explicitly shares the value or captures its context and shares it. Same as with threading.local.

2) Would an appropriate use of this API be to assign a unique task id to each task? Or can that be handled more simply? I'm wondering because I recently thought this would be useful, and it doesn't seem like asyncio means for one to subclass Task (though I could be wrong).

The API should be used to share one ID between a Task and tasks it creates. You can use it to store individual Task IDs, but a combination of a WeakKeyDictionary and Task.current_task() seems to be a better/easier option.

Yury



More information about the Python-Dev mailing list