Skip to content
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

Document workaround to run a text-mode browser in a subprocess #96

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

blag
Copy link
Contributor

@blag blag commented Sep 3, 2024

I figured this out to support an OAuth flow within a Dockerized environment, but it might also be helpful for other authentication backends.

According to the webbrowser module documentation:

For non-Unix platforms, or when a remote browser is available on Unix, the controlling process will not wait for the user to finish with the browser, but allow the remote browser to maintain its own windows on the display. If remote browsers are not available on Unix, the controlling process will launch a new browser and wait.

When you are running a project in a containerized environment, you probably don't have access to a graphical interface. In that case, webbrowser.open() blocks and waits for the text-mode browser to close. However, the opened browser attempts to load the content provided by httpx-auth's authentication response server. This becomes a deadlock - the browser is loading content from the auth response server, but the auth response server cannot send the content because it is blocking on the webbrowser.

The webbrowser module already has support for opening a text-mode browser in a non-blocking fashion:

        if '%s' in browser:
            # User gave us a command line, split it into name and args
            browser = shlex.split(browser)
            if browser[-1] == '&':
                return BackgroundBrowser(browser[:-1])
            else:
                return GenericBrowser(browser)

This PR simply documents how to correctly trigger the preexisting functionality to open a text-mode browser in a separate process.

@blag blag force-pushed the add-text-mode-webbrowser-note branch from a6d1024 to e67de54 Compare September 3, 2024 03:15
Copy link

sonarcloud bot commented Sep 3, 2024

@blag
Copy link
Contributor Author

blag commented Sep 3, 2024

Since this is just a documentation update, I suspect that the test failures are unrelated, or need to be rerun.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant