-
-
Notifications
You must be signed in to change notification settings - Fork 31.2k
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
python3 futures.as_completed timeout broken if future contains undefined reference #85860
Comments
I recently noticed that timeouts do not work with futures.as_completed if a future contains an undefined variable or method. The following code runs for 30 seconds which I believe is a bug as I would expect the invalid print future to throw an exception immediately or the as_completed method throw an exception instead. ######################### import concurrent.futures
with concurrent.futures.ThreadPoolExecutor() as ex:
futures = [
ex.submit(time.sleep, 30),
ex.submit(print, a),
]
for future in concurrent.futures.as_completed(futures, timeout=1):
_ = future.result() |
After closer inspection it seems as though timeouts are not working as I would expect even when there are no undefined references. The following code runs for 30s when I would expect a timeout exception thrown after 1 second. as_completed eventually does throw a timeout exception, but only after the sleep future completes. ############################### import concurrent.futures
import time
with concurrent.futures.ThreadPoolExecutor() as ex:
futures = [
ex.submit(time.sleep, 30),
ex.submit(print, 'test'),
]
for future in concurrent.futures.as_completed(futures, timeout=1):
_ = future.result() |
I also verified that this issue persists with blocking futures other than sleep calls: import concurrent.futures
import subprocess
with concurrent.futures.ThreadPoolExecutor() as ex:
futures = [
ex.submit(subprocess.run, ['sleep', '30']),
ex.submit(print, 'test'),
]
for future in concurrent.futures.as_completed(futures, timeout=1):
_ = future.result() |
I apologize for all the messages, but the more I look into this issue the stranger it seems. The following code does the following:
the second time print executes after the as_completed timeout duration, but the exception was only raised after all futures completed. the exception message incorrectly states that it left 2/3 futures unfinished. ######################### import concurrent.futures
import time
with concurrent.futures.ThreadPoolExecutor() as ex:
print(time.time())
futures = [
ex.submit(time.sleep, 30),
ex.submit(time.sleep, 30),
ex.submit(print, 'test'),
]
try:
for future in concurrent.futures.as_completed(
futures, timeout=1):
_ = future.result()
except Exception as e:
print(time.time())
raise e |
The problem is a lot simpler than you're making it:
All of this is behaving exactly as documented, no bug is occurring. |
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:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: