[issue45689] Add the ability to give custom names to threads created by ThreadPoolExecutor

Mark Dickinson report at bugs.python.org
Tue Nov 9 12:51:14 EST 2021


Mark Dickinson <dickinsm at gmail.com> added the comment:

Sorry Rahul: I'm not the right person to help you push this forward.

I'm sympathetic to the problem: I've encountered similar issues in "Real Code", where we needed to associate log outputs generated by worker pool threads with the actual tasks that generated those logs. But I'm not convinced either that setting the thread name is the right mechanism to get that association (it doesn't extend nicely to other executor types, for example), or that the API you propose is the right one (I find the duplication between `submit` and `submit_with_name` to be a bit much).

I'm wondering whether there's some way that executors could use contextvars to provide a per-task context. Then a task "name" could potentially be part of that context, and possibly you could write a custom log handler that read the name from the context when emitting log messages.

If you want to find someone to help push this forward, it may be worth posting on the python-ideas mailing list to get discussion going.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue45689>
_______________________________________


More information about the Python-bugs-list mailing list