Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-124694: Document missing ctxkwargs argument in ThreadPoolExecutor#134321

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
donBarbos wants to merge4 commits intopython:main
base:main
Choose a base branch
Loading
fromdonBarbos:issue-124694-docs

Conversation

donBarbos
Copy link
Contributor

@donBarbosdonBarbos commentedMay 20, 2025
edited
Loading

@donBarbos
Copy link
ContributorAuthor

cc@picnixz

@picnixzpicnixz added the needs backport to 3.14bugs and security fixes labelMay 20, 2025
@@ -287,7 +292,8 @@ efficient alternative is to serialize with :mod:`pickle` and then send
the bytes over a shared :mod:`socket <socket>` or
:func:`pipe <os.pipe>`.

.. class:: InterpreterPoolExecutor(max_workers=None, thread_name_prefix='', initializer=None, initargs=(), shared=None)
.. class:: InterpreterPoolExecutor(max_workers=None, thread_name_prefix='', \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This is unrelated, but it's probably an improvement as it's now more readable. So I'm ok with it.

donBarbos reacted with thumbs up emoji
Copy link
Member

@picnixzpicnixz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I don't know if the parameters are meant to be public but the signature indeed needs to be correct for possible subclassing.

However,prepare_context is not documented so we can't even know how to use them. So we need to also document this at the same time.

@donBarbos
Copy link
ContributorAuthor

I don't know if the parameters are meant to be public but the signature indeed needs to be correct for possible subclassing.

ctxkwargs argument described inThreadPoolExecutor.__init__ docstring.

And maybe I'm missing something but this is what the class methodprepare_context looks like (I don't know how**ctxkwargs should be passed here if this argument is omitted inprepare_context):

@classmethod
defprepare_context(cls,initializer,initargs):
returnWorkerContext.prepare(initializer,initargs)
def__init__(self,max_workers=None,thread_name_prefix='',
initializer=None,initargs=(),**ctxkwargs):
"""Initializes a new ThreadPoolExecutor instance.
Args:
max_workers: The maximum number of threads that can be used to
execute the given calls.
thread_name_prefix: An optional name prefix to give our threads.
initializer: A callable used to initialize worker threads.
initargs: A tuple of arguments to pass to the initializer.
ctxkwargs: Additional arguments to cls.prepare_context().
"""
ifmax_workersisNone:
# ThreadPoolExecutor is often used to:
# * CPU bound task which releases GIL
# * I/O bound task (which releases GIL, of course)
#
# We use process_cpu_count + 4 for both types of tasks.
# But we limit it to 32 to avoid consuming surprisingly large resource
# on many core machine.
max_workers=min(32, (os.process_cpu_count()or1)+4)
ifmax_workers<=0:
raiseValueError("max_workers must be greater than 0")
(self._create_worker_context,
self._resolve_work_item_task,
)=type(self).prepare_context(initializer,initargs,**ctxkwargs)

@picnixz
Copy link
Member

And maybe I'm missing something but this is what the class method prepare_context looks like (I don't know how **ctxkwargs should be passed here if this argument is omitted in prepare_context):

in this case, we should wait for Eric's feedback. I'm away until Saturday so I won't be able to reply in the meantime.

class method.

.. classmethod:: prepare_context(initializer, initargs)
Setting up the necessary context for creating worker instances in a pool-based executor (e.g., in a concurrent environment like threads or interpreters).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
Setting up the necessary context for creating worker instances in a pool-based executor (e.g., in a concurrent environment like threads or interpreters).
Setting up the necessary context for creating worker instances in a pool-based executor (for example, in a concurrent environment like threads or interpreters).

Use simple language and this line needs wrapping

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@picnixzpicnixzpicnixz left review comments

@StanFromIrelandStanFromIrelandStanFromIreland left review comments

@ericsnowcurrentlyericsnowcurrentlyAwaiting requested review from ericsnowcurrently

Assignees
No one assigned
Labels
awaiting reviewdocsDocumentation in the Doc dirneeds backport to 3.14bugs and security fixesskip news
Projects
Status: Todo
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@donBarbos@picnixz@StanFromIreland

[8]ページ先頭

©2009-2025 Movatter.jp