Unexpected program hang after exception is raised while iterating a generator
See original GitHub issue- Package Name: azure-servicebus
- Package Version: 7.4.0
- Operating System: GNU/Linux
- Python Version: 3.9.9
Strangely, the following program does not terminate:
from azure.identity import DefaultAzureCredential
from azure.servicebus import (
ServiceBusClient,
ServiceBusReceiveMode,
)
def receive():
namespace = 'xxx'
topic = 'yyy'
subscription = 'zzz'
credential = DefaultAzureCredential()
client = ServiceBusClient(
fully_qualified_namespace=f'{namespace}.servicebus.windows.net',
credential=credential,
)
with client as client:
receiver = client.get_subscription_receiver(
topic_name=topic,
subscription_name=subscription,
receive_mode=ServiceBusReceiveMode.PEEK_LOCK,
)
with receiver as receiver:
for message in receiver:
yield message
def main():
messages = receive()
for message in messages:
raise Exception('Terminate program.')
if __name__ == '__main__':
main()
It prints the exception and hangs:
Traceback (most recent call last):
File "/home/indy/dm/sb-experiment/./sbexperiment/app.py", line 40, in <module>
main()
File "/home/indy/dm/sb-experiment/./sbexperiment/app.py", line 36, in main
raise Exception('Terminate program.')
Exception: Terminate program.
But it works as expected when I modify main()
to this:
def main():
for message in receive():
raise Exception('Terminate program.')
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:11 (7 by maintainers)
Top Results From Across the Web
python - Handle an exception thrown in a generator
When a generator throws an exception, it exits. You can't continue consuming the items it generates. Example: >>> def f(): ... yield 1...
Read more >PEP 479 – Change StopIteration handling inside generators
An unexpected exception should not result in subtly altered behaviour, but should cause a noisy and easily-debugged traceback. Currently, StopIteration raised ...
Read more >Cleaning Up in a Python Generator Can Be Dangerous
If the generator yields a value, a RuntimeError is raised. If the generator raises any other exception, it is propagated to the caller....
Read more >Fix list for IBM WebSphere Application Server V8.5
AppServers go into retry cycle with error message "exception caught increasing range of unique key generator!" Migration, PH36102, MIGR0285E: an unexpected ...
Read more >Pylint features - Pylint 2.16.0-dev documentation
When you raise a new exception after another exception was caught it's likely that the second exception is a friendly re- wrapping of...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hey @Indy2222 - apologies for the late update! I’ll make sure to discuss this with the team this upcoming week and keep you posted on when we can address this. Thanks!
Hey @Indy2222 - Appreciate your feedback on this! We have a few other issues taking priority at the moment, but we plan to address this as soon as possible. Thank you!