[issue34996] Add name to process and thread pool

Karthikeyan Singaravelan report at bugs.python.org
Mon Oct 22 03:26:52 EDT 2018


Karthikeyan Singaravelan <tir.karthi at gmail.com> added the comment:

Thanks for clarifying the use case. I think it's a good idea with multiple thread pools and below outputs for the program with the PR is more easier to debug than the current code. 

# ../backups/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__':
    p1 = ThreadPool(5, name="process-1")
    p1.map_async(f, [1, 2, 3])
    p1.close()

    p2 = ThreadPool(5, name="process-2")
    p2.map_async(f, [1, 2, 3])
    p2.close()

    p1.join()
    p2.join()

# With patch

$ ./python.exe ../backups/bpo34720.py
process-1-Worker-0
process-1-Worker-1
process-1-Worker-0
process-2-Worker-0
process-2-Worker-1
process-2-Worker-0

# Without patch and removing name parameter

$ python3.7 ../backups/bpo34720.py
Thread-1
Thread-1
Thread-1
Thread-9
Thread-9
Thread-9

----------

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


More information about the Python-bugs-list mailing list