question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:open
  • Created 2 years ago
  • Reactions:1
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
swathipilcommented, Apr 22, 2022

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!

1reaction
swathipilcommented, Jan 19, 2022

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!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found