-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
bpo-38267: Add thread timeout parameter to loop.shutdown_default_executor()
#16360
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
Changes from 24 commits
700cf86
1e7794b
a262c45
b1bb810
8a4c30c
ebc1b99
5b90766
f189f04
16921a1
b678818
e332257
7f8428b
577b2b2
b673080
926de3f
f7c623c
169d2d4
f0dde2d
b7c0608
1e95afb
2b1f35d
e549996
8a5121c
4264c04
e9a0f19
d9c2e37
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -549,8 +549,13 @@ async def shutdown_asyncgens(self): | |
'asyncgen': agen | ||
}) | ||
|
||
async def shutdown_default_executor(self): | ||
"""Schedule the shutdown of the default executor.""" | ||
async def shutdown_default_executor(self, timeout=None): | ||
"""Schedule the shutdown of the default executor. | ||
|
||
The timeout parameter specifies the amount of time the threadpool will | ||
be given to finish joining. The default value is None, which means | ||
that the threadpool will be given an indefinite amount of time. | ||
""" | ||
self._executor_shutdown_called = True | ||
if self._default_executor is None: | ||
return | ||
|
@@ -560,7 +565,13 @@ async def shutdown_default_executor(self): | |
try: | ||
await future | ||
finally: | ||
thread.join() | ||
thread.join(timeout) | ||
|
||
if (thread.is_alive()): | ||
gvanrossum marked this conversation as resolved.
Show resolved
Hide resolved
|
||
warnings.warn("The ThreadPoolExecutor did not finishing joining" | ||
f"its threads within {timeout} seconds.", | ||
RuntimeWarning) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @1st1 Couple of questions regarding the warning:
Edit: Regarding the test, I don't think there's a way to test for this without creating a dangling thread due to the nature of the warning. Personally, I don't think it's worth adding an intentional resource leak to the asyncio regression tests just to test the functionality of a single warning. If there's another way to test for the warning without creating a dangling thread, let me know. |
||
self._default_executor.shutdown(wait=False) | ||
|
||
def _do_shutdown(self, future): | ||
try: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Add *timeout* parameter to :meth:`asyncio.loop.shutdown_default_executor`. |
Uh oh!
There was an error while loading. Please reload this page.