GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — bpo-24241: Preferred X browser by davesteele · Pull Request #85 · python/cpython

Conversation

@davesteele

@davesteele davesteele commented Feb 14, 2017

Copy link
Copy Markdown
Contributor

When calling webbrowser.open*(), the module goes through a list of installed browsers, and uses the first one that succeeds, to process the request.

The first 'browsers' in the 'X' list are 'xdg-open' and others of that ilk. The problem is that they only have one 'open' behavior - the 'new' parameter is ignored ('same window', 'new window', 'new tab').

These commits move the default web browser to the front of the tryorder list, allowing get() behavior to match the documentation.

This same problem was recently fixed in Windows via Issue #8232

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@the-knights-who-say-ni the-knights-who-say-ni added the CLA not signed label Feb 14, 2017
@the-knights-who-say-ni

the-knights-who-say-ni commented Feb 14, 2017

Copy link
Copy Markdown

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept your contribution by verifying you have signed the PSF contributor agreement (CLA).

Unfortunately we couldn't find an account corresponding to your GitHub username on bugs.python.org (b.p.o) to verify you have signed the CLA. This is necessary for legal reasons before we can look at your contribution. Please follow these steps to help rectify the issue:

  1. If you don't have an account on b.p.o, please create one
  2. Make sure your GitHub username is listed in "Your Details" at b.p.o
  3. If you have not already done so, please sign the PSF contributor agreement
  4. If you just signed the CLA, please wait at least one US business day and then check "Your Details" on bugs.python.org to see if your account has been marked as having signed the CLA (the delay is due to a person having to manually check your signed CLA)
  5. Reply here saying you have completed the above steps

Thanks again to your contribution and we look forward to looking at it!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@davesteele davesteele changed the title Issue #24241: Preferred X browser bpo-24241: Preferred X browser Feb 14, 2017
@davesteele

davesteele commented Feb 14, 2017

Copy link
Copy Markdown
Contributor Author

I've tied my bpo 'daves' account to github 'davesteele'. The contributor form was received 2015-07-17.00:00:00.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@codecov

codecov Bot commented Feb 14, 2017

Copy link
Copy Markdown

Codecov Report

Merging #85 into master will decrease coverage by -0.01%.
The diff coverage is 14.28%.

@@            Coverage Diff             @@
##           master      #85      +/-   ##
==========================================
- Coverage   82.38%   82.38%   -0.01%     
==========================================
  Files        1428     1428              
  Lines      351138   351143       +5     
==========================================
- Hits       289291   289275      -16     
- Misses      61847    61868      +21

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b692dc8...602ba9f. Read the comment docs.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@zware zware removed the CLA not signed label Feb 14, 2017
@the-knights-who-say-ni the-knights-who-say-ni added the CLA signed label Feb 14, 2017
ultimatecoder
ultimatecoder reviewed Feb 18, 2017
View reviewed changes

@ultimatecoder ultimatecoder left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found improvements to the code.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Lib/webbrowser.py Outdated

@ultimatecoder ultimatecoder Feb 18, 2017

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure you should pass the exceptions silently.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@davesteele davesteele Feb 18, 2017

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what to report, otherwise. Passing on the FileNotFoundError feels right to me.

I could drop catching CalledProcessError?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@merwok merwok Feb 18, 2017

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could use shutil.which to determine if xdg-settings exists before trying to call it (LBYL). But here ignoring the exception (EAFP) seems right to me.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@ncoghlan ncoghlan Feb 19, 2017

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With a _preferred_browsers set, this would become:

try:
    cmd = "xdg-settings get default-web-browser".split()
    _xdg_default_browser = subprocess.check_output(cmd).decode().strip()
except (FileNotFoundError, subprocess.CalledProcessError):
     pass
else:
    _preferred_browsers.add(_xdg_default_browser)

I believe that would be more self-explanatory as to the purpose of ignoring the exceptions here (if we fail to find the xdg default browser, we simply don't add it to the preferred browser set)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
ultimatecoder
ultimatecoder suggested changes Feb 18, 2017
View reviewed changes

@ultimatecoder ultimatecoder left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will suggest updating the documentation for method register at Doc/library/webbrowser.rst

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
merwok
merwok reviewed Feb 18, 2017
View reviewed changes
Comment thread Lib/webbrowser.py Outdated

@merwok merwok Feb 18, 2017

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it’s good to change the signature here. Is it impossible to give high priority to the browser found with xdg-settings, if any, with the update_tryorder param?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@davesteele davesteele Feb 18, 2017

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took the opportunity to make what I thought was an improvement. The tri-state definition of the old parameter seemed a bit clumsy and unnecessary (note that it was left out of the documentation).

I can back out the change to update_tryorder if it is deemed appropriate.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@ncoghlan ncoghlan Feb 19, 2017

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest making the parameter preferred rather than priority and making it keyword-only.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@davesteele

davesteele commented Feb 18, 2017

Copy link
Copy Markdown
Contributor Author

I've added documentation for the register() priority argument.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

ncoghlan
ncoghlan requested changes Feb 19, 2017
View reviewed changes

@ncoghlan ncoghlan left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the general idea of this patch, but think it would be more self-explanatory with some changes to the specific implementation details.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Lib/webbrowser.py Outdated

@ncoghlan ncoghlan Feb 19, 2017

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than only allowing a single preferred browser, perhaps it would make sense to make this a _preferred_browsers set? That would have a ripple effect on the other updates below.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@davesteele davesteele Feb 19, 2017

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My original implementation did this, but I didn't find the enhancement useful. There weren't any ripples.

That said, I'll make the change if this is considered a blocker.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Lib/webbrowser.py Outdated

@ncoghlan ncoghlan Feb 19, 2017

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With a set, this condition would become if priority or name in _preferred_browsers:

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@davesteele davesteele Feb 19, 2017

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'preferred' is a better name. I'll make the change.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@davesteele davesteele Feb 19, 2017

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had managed to make it to this point without encountering the keyword-only concept in the library (or elsewhere, for that matter). Would this cause unnecessary confusion?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@davesteele davesteele Feb 19, 2017

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that 'name in _preferred_browsers' is not enough. xdg-settings returns e.g. 'firefox.desktop'.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@ncoghlan ncoghlan Feb 23, 2017

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keyword-only is our preferred approach to handling boolean arguments in Python 3, as otherwise you end up with code that's ambiguous at the point of calling (as here, where the True conveys no info to a reader that doesn't already know the signature, while preferred=True is a lot more descriptive)

Regarding _preferred_browser potentially needing to match things like firefox against firefox.desktop, that belongs in an explanatory comment in the code itself. I'm fine with dropping the idea of switching to a set, though.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@ncoghlan ncoghlan Feb 23, 2017

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A slight name tweak may help convey the difference between this field and the new parameter to register though: what do you think about renaming it to _os_preferred_browser?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Lib/webbrowser.py Outdated

@ncoghlan ncoghlan Feb 19, 2017

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With a _preferred_browsers set, this would become:

try:
    cmd = "xdg-settings get default-web-browser".split()
    _xdg_default_browser = subprocess.check_output(cmd).decode().strip()
except (FileNotFoundError, subprocess.CalledProcessError):
     pass
else:
    _preferred_browsers.add(_xdg_default_browser)

I believe that would be more self-explanatory as to the purpose of ignoring the exceptions here (if we fail to find the xdg default browser, we simply don't add it to the preferred browser set)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Lib/webbrowser.py Outdated

@ncoghlan ncoghlan Feb 19, 2017

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest making the parameter preferred rather than priority and making it keyword-only.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Lib/webbrowser.py Outdated

@ncoghlan ncoghlan Feb 19, 2017

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the above suggested change to the signature of register, this and the other options below would become:

register("safari", None, MacOSXOSAScript('safari'), preferred=True)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@davesteele davesteele Feb 19, 2017

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add the 'else' construct.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@codecov-io

codecov-io commented Feb 19, 2017

Copy link
Copy Markdown

Codecov Report

Merging #85 into master will decrease coverage by -0.01%.
The diff coverage is 13.33%.

@@            Coverage Diff             @@
##           master      #85      +/-   ##
==========================================
- Coverage   82.38%   82.37%   -0.01%     
==========================================
  Files        1428     1428              
  Lines      351138   351206      +68     
==========================================
+ Hits       289291   289317      +26     
- Misses      61847    61889      +42

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b692dc8...795ee09. Read the comment docs.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@davesteele

davesteele commented Feb 19, 2017

Copy link
Copy Markdown
Contributor Author

@ncoghlan, I've made some changes based on your review, and pushed back on a few others. You be the final arbiter on the issues. Let me know.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ncoghlan

ncoghlan commented Feb 23, 2017

Copy link
Copy Markdown
Contributor

+1 on leaving the helper variable as a single string - I've suggested a name change and an additional explanatory comment to cover some of the subtleties for future maintainers.

For the preferred change, I still think keyword-only arguments will be clearer, as preferred=True conveys a lot more information at the call sites than a bare True.

The commit message also still needs adjustment to better cover the changes being made (i.e. both the preferred parameter being added to webbrowser.register, and the module being updated to use xdg-settings to find the appropriate preferred browser on Linux).

If you're so inclined, you could also add an entry to the 3.7 What's New for this change (otherwise I'll just add it along with the NEWS entry when pushing the change)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

davesteele added 2 commits February 24, 2017 16:27
@davesteele
webbrowser.register: Add 'preferred' argument
30a06fd
Replace the existing undocumented tri-state 'try_order' parameter with
the boolean keyword-only 'preferred' parameter. Setting it to True
places the browser at the front of the list, preferring it as the return
to a subsequent get() call.

'preferred' is added to the documentation.
@davesteele
bpo-24241: xdg-settings for preferred X browser
871455f
The traditional first entry in the tryorder queue is xdg-open, which
doesn't support new window. Make the default browser first
in the try list, to properly support these options.
@davesteele
davesteele force-pushed the preferred_browser branch from 795ee09 to 871455f Compare February 24, 2017 21:37
@davesteele

davesteele commented Feb 24, 2017

Copy link
Copy Markdown
Contributor Author

@ncoghlan, I've reworked, reworded, and rebased the commits based on your suggestions.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

ncoghlan
ncoghlan approved these changes Feb 25, 2017
View reviewed changes
@ncoghlan

ncoghlan commented Feb 25, 2017

Copy link
Copy Markdown
Contributor

The codecov complaints are due to CI not running on Mac OS X, so this looks good to me now - merging!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ncoghlan
ncoghlan merged commit e3ce695 into python:master Feb 25, 2017
@davesteele

davesteele commented Feb 25, 2017

Copy link
Copy Markdown
Contributor Author

Thanks for your help on this.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ncoghlan ncoghlan mentioned this pull request Feb 25, 2017
Require code coverage not drop in a PR python/core-workflow#38
Closed
@ncoghlan ncoghlan added the sprint label May 28, 2017
@ncoghlan

ncoghlan commented May 28, 2017

Copy link
Copy Markdown
Contributor

Added the sprint label, as this PR was submitted at the PyCon Pune 2017 core development sprint.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

akruis pushed a commit to akruis/cpython that referenced this pull request Sep 9, 2017
Anselm Kruis
Stackless issue python#85: Failed assertion caused by PyStackless_Run…
deaf98c
…WatchdogEx

Fix issue python#85: don't schedule already scheduled tasklets.
Ensure that the internal watchdog list is empty before and after
all test cases of class TestNewWatchdog.

Fix test case TestNewWatchdog.test_watchdog_priority_{hard|soft}. The
timeout value was much to short to build up a list of watchdogs.

The new test cases TestNewWatchdog.test_schedule_deeper_{hard|soft}
triggers the assertion failure reliably. They are skipped for now.

https://bitbucket.org/stackless-dev/stackless/issues/85
(grafted from 2235702eb90cb0709dd40544b3952a956f2032a9 and 3fb55ce5b2d4)
akruis pushed a commit to akruis/cpython that referenced this pull request Sep 9, 2017
Anselm Kruis
Enable a skiped test case for issue python#85
f76353a
akruis pushed a commit to akruis/cpython that referenced this pull request Sep 9, 2017
Anselm Kruis
merge 3.4-slp (Stackless python#81, python#85)
4717ee3
colesbury referenced this pull request in colesbury/nogil Oct 6, 2021
@colesbury
ParkingLot: use thread-local waiter instead of PyThreadState
083382d
Sometimes we need to acquire locks before the current PyThreadState
is set. This moves the waiter data to it's own struct. It's shared
between PyThreadStates on the same thread, such as in multi-interpreter
settings.

Fixes #85
jaraco pushed a commit that referenced this pull request Dec 2, 2022
@pyup-bot @asvetlov
Update aiohttp from 3.1.1 to 3.2.0 (#85)
443d0dd
markshannon pushed a commit to faster-cpython/cpython that referenced this pull request Jan 10, 2023
@colesbury
Merge pull request python#85 from lesteve/docker-build-push
1761801
Add github workflow to build and publish docker image
@gvanrossum gvanrossum mentioned this pull request Aug 22, 2023
heap-use-after-free in _PyFunction_LookupByVersion #108253
Closed
@ngoldbaum ngoldbaum mentioned this pull request Sep 23, 2024
Crash running PyO3 tests with --test-threads=1000 #124375
Closed
This was referenced Feb 11, 2025
segmentfault when pip installing setuptools #129992
Closed
segmentfault when pip installing setuptools #129993
Closed
@sergey-miryanov sergey-miryanov mentioned this pull request Dec 18, 2025
Observed memory leak in ssl library: Python 3.14 GC issue #142516
Closed
@ngoldbaum ngoldbaum mentioned this pull request Mar 6, 2026
Remove deprecated and undocumented function ctypes.SetPointerType #133866
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@merwok merwok merwok left review comments
@ncoghlan ncoghlan ncoghlan approved these changes
+1 more reviewer
@ultimatecoder ultimatecoder ultimatecoder requested changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

sprint

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

7 participants

@davesteele @the-knights-who-say-ni @codecov-io @ncoghlan @merwok @ultimatecoder @zware
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.