Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow specifying prefix for thread name in concurrent.futures.ThreadPoolExecutor #71851

Closed
durin42 mannequin opened this issue Aug 1, 2016 · 4 comments
Closed

Allow specifying prefix for thread name in concurrent.futures.ThreadPoolExecutor #71851

durin42 mannequin opened this issue Aug 1, 2016 · 4 comments
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@durin42
Copy link
Mannequin

durin42 mannequin commented Aug 1, 2016

BPO 27664
Nosy @gpshead
Files
  • cpython.patch: Initial patch.
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2016-08-07.17:20:38.633>
    created_at = <Date 2016-08-01.18:03:16.648>
    labels = ['type-feature', 'library']
    title = 'Allow specifying prefix for thread name in concurrent.futures.ThreadPoolExecutor'
    updated_at = <Date 2016-08-07.17:20:38.631>
    user = 'https://bugs.python.org/durin42'

    bugs.python.org fields:

    activity = <Date 2016-08-07.17:20:38.631>
    actor = 'gregory.p.smith'
    assignee = 'none'
    closed = True
    closed_date = <Date 2016-08-07.17:20:38.633>
    closer = 'gregory.p.smith'
    components = ['Library (Lib)']
    creation = <Date 2016-08-01.18:03:16.648>
    creator = 'durin42'
    dependencies = []
    files = ['43967']
    hgrepos = []
    issue_num = 27664
    keywords = ['patch']
    message_count = 4.0
    messages = ['271790', '272125', '272126', '272127']
    nosy_count = 3.0
    nosy_names = ['gregory.p.smith', 'durin42', 'python-dev']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'commit review'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue27664'
    versions = ['Python 3.6']

    @durin42
    Copy link
    Mannequin Author

    durin42 mannequin commented Aug 1, 2016

    This is mostly useful for when you've got a large number of threads and want to try and identify what threadpool is going nuts.

    @durin42 durin42 mannequin added stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels Aug 1, 2016
    @gpshead
    Copy link
    Member

    gpshead commented Aug 7, 2016

    A workaround for this on 3.5 and older versions is probably to do:

    initialization:

    num_q = queue.Queue()
    map(num_q.put, range(max_workers))

    Then schedule max_workers identical tasks:

    def task():
      threading.current_thread().name = '%s_%d' % (your_prefix, num_q.get())
      num_q.task_done()
      num_q.join()  # block so that this thread cannot take a new thread naming task until all other tasks are complete.  guaranteeing we are executed once per max_workers threads.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Aug 7, 2016

    New changeset 1002a1bdc5b1 by Gregory P. Smith in branch 'default':
    Issue bpo-27664: Add to concurrent.futures.thread.ThreadPoolExecutor()
    https://hg.python.org/cpython/rev/1002a1bdc5b1

    @gpshead
    Copy link
    Member

    gpshead commented Aug 7, 2016

    cleaned up a bit with documentation added and submitted. thanks. ThreadPoolExecutor threads now have a default name as well, because why not.

    @gpshead gpshead closed this as completed Aug 7, 2016
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant