Skip to content

acquire_token_interactive can't be stopped by Ctrl+C #393

@jiasli

Description

@jiasli

Describe the bug

PublicClientApplication.acquire_token_interactive can't be stopped by Ctrl+C.

To Reproduce

  1. Call PublicClientApplication.acquire_token_interactive
  2. Press Ctrl+C

Expected behavior

MSAL should respond to KeyboardInterrupt.

What you see instead

The terminal hangs. The only way to stop it is Ctrl+Break (https://stackoverflow.com/questions/1364173/stopping-python-using-ctrlc).

The MSAL Python version you are using

1.13.0

Additional context

Azure CLI runs HTTPServer on a daemon thread so that Ctrl+C can stop the main thread which is time.sleeping: https://github.com/Azure/azure-cli/blob/a4d84cc6e7fb6bd741753cb6a52410d0397c56c3/src/azure-cli-core/azure/cli/core/_profile.py#L1383-L1397

Another possible solution is to call HTTPServer.serve_forever. This is the approach of http.server when we run

python -m http.server 8000

Per socketserver.BaseServer.serve_forever, it internally resumes control to the main thread every poll_interval seconds so that KeyboardInterrupt can be handled.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions