Karthikeyan Singaravelan <[email protected]> added the comment:
Thanks for the report. I think using current_thread().name gives thread name
with number that is useful. I don't know the exact use case or maybe I am
misunderstanding the use case and perhaps adding a script where your PR applies
with the output will be helpful. I will resort to feedback from others. Adding
Antoine as per the expert index for multiprocessing module. Antoine, feel free
to remove yourself if this is irrelevant.
# bpo34720.py
from multiprocessing.pool import ThreadPool
def f(x):
from threading import current_thread
print(current_thread().name)
return x*x
if __name__ == '__main__':
with ThreadPool(5) as p:
print(p.map(f, [1, 2, 3]))
$ ./python.exe ../backups/bpo34720.py
Thread-1
Thread-1
Thread-2
[1, 4, 9]
# With PR and name as "custom-name" for ThreadPool
from multiprocessing.pool import ThreadPool
def f(x):
from threading import current_thread
print(current_thread().name)
return x*x
if __name__ == '__main__':
with ThreadPool(5, name="custom-name") as p:
print(p.map(f, [1, 2, 3]))
git:(pr_9906) ./python.exe ../backups/bpo34720.py
custom-name-Worker-0
custom-name-Worker-1
custom-name-Worker-2
[1, 4, 9]
----------
nosy: +pitrou, xtreak
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue34996>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com