Movatterモバイル変換


[0]ホーム

URL:


homepage

Issue29645

This issue trackerhas been migrated toGitHub, and is currentlyread-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title:webbrowser module import has heavy side effects
Type:performanceStage:resolved
Components:Library (Lib)Versions:Python 3.7
process
Status:closedResolution:fixed
Dependencies:Superseder:
Assigned To:Nosy List: louielu, ncoghlan, serhiy.storchaka, terry.reedy
Priority:normalKeywords:patch

Created on2017-02-25 09:26 byserhiy.storchaka, last changed2022-04-11 14:58 byadmin. This issue is nowclosed.

Files
File nameUploadedDescriptionEdit
webbrowser-delayed-initialization.patchserhiy.storchaka,2017-02-25 11:48
webbrowser-delayed-initialization-2.patchserhiy.storchaka,2017-02-25 22:50
Pull Requests
URLStatusLinkedEdit
PR 484mergedserhiy.storchaka,2017-03-05 21:38
PR 703larry,2017-03-17 21:00
Messages (10)
msg288551 -(view)Author: Serhiy Storchaka (serhiy.storchaka)*(Python committer)Date: 2017-02-25 09:26
`import webbrowser` has heavy side effects. It searches a number of executables. On X Window it also runs external program xdg-settings.Cold start:$ time ./python -c ''real0m1.719suser0m0.088ssys0m0.036s$ time ./python -c 'import webbrowser'real0m5.713suser0m0.308ssys0m0.196sHot start:$ time ./python -c ''real0m0.094suser0m0.072ssys0m0.020s$ time ./python -c 'import webbrowser'real0m1.026suser0m0.284ssys0m0.100s
msg288561 -(view)Author: Louie Lu (louielu)*Date: 2017-02-25 11:38
What is the different of Cold start and Hot start? It that CPU speed or something else.In Linux 4.9.11 with i7-2k, I can't reproduce the significant real time you gave:# CPU gov powersave$ time ./python -c 'import webbrowser'0.16s user 0.02s system 93% cpu 0.200 total# CPU gov performance$ time ./python -c 'import webbrowser'0.08s user 0.00s system 82% cpu 0.093 total
msg288562 -(view)Author: Serhiy Storchaka (serhiy.storchaka)*(Python committer)Date: 2017-02-25 11:47
Following patch makes searching of all platform browsers delayed until it is needed. In addition it makes webbrowser.register() thread safe.Cold start:$ time ./python -c 'import webbrowser'real0m2.851suser0m0.224ssys0m0.056sHot start:$ time ./python -c 'import webbrowser'real0m0.259suser0m0.232ssys0m0.024s
msg288563 -(view)Author: Serhiy Storchaka (serhiy.storchaka)*(Python committer)Date: 2017-02-25 11:55
> What is the different of Cold start and Hot start?Disk caches are dropped before cold start.$ echo 3 | sudo tee /proc/sys/vm/drop_caches
msg288566 -(view)Author: Alyssa Coghlan (ncoghlan)*(Python committer)Date: 2017-02-25 14:52
Nice, this is much cleaner than the current approach!The one thing I would suggest is a new test case that:- asserts webbrowser._tryorder is None- asserts webbrowser._browsers is empty- calls webbrowser.get()- asserts webbrowser._tryorder is non-empty- asserts webbrowser._browsers is non-emptyI wouldn't worry about explicitly testing the thread safety. That's just a normal double-checked locking pattern, so I think code review is sufficient to address that - the only way for it to break is for something to go horribly wrong in threading.RLock().
msg288585 -(view)Author: Serhiy Storchaka (serhiy.storchaka)*(Python committer)Date: 2017-02-25 22:50
Added tests.
msg288587 -(view)Author: Alyssa Coghlan (ncoghlan)*(Python committer)Date: 2017-02-26 03:43
Patch LGTM.Serhiy, did you want to take this as a chance to run through the new GitHub PR workflow?Current details are athttps://docs.python.org/devguide/pullrequest.html
msg288589 -(view)Author: Serhiy Storchaka (serhiy.storchaka)*(Python committer)Date: 2017-02-26 07:14
The new GitHub PR workflow still looks cumbersome and unclear to me. It needs using a lot of git commands different for different branches (and some command are failed or don't work as I expected when I try to repeat sequences from thedevguide). How to convert a patch to a pull request? How to get a list of added and modified files? What is the best way to revert all changes and changes in selected files? How to retrieve changes from pull request for local testing? Is there a way to edit otherpeople's pull request (add an entry inMisc/NEWS, etc) before merging it in the main repository? I wait until thedevguide be more comprehensive.
msg288930 -(view)Author: Terry J. Reedy (terry.reedy)*(Python committer)Date: 2017-03-03 21:16
This will help IDLE startup (though webbrowser should not be imported on windows, where os.startfile is used instead).This is a somewhat separate issue, but should the Windows code be modified for Win10 and Microsoft Edge?
msg290260 -(view)Author: Serhiy Storchaka (serhiy.storchaka)*(Python committer)Date: 2017-03-24 22:40
New changeseta7cba27aea138311117e2ab1d91584efcfeac4ec by Serhiy Storchaka in branch 'master':bpo-29645: Speed up importing the webbrowser module. (#484)https://github.com/python/cpython/commit/a7cba27aea138311117e2ab1d91584efcfeac4ec
History
DateUserActionArgs
2022-04-11 14:58:43adminsetgithub: 73831
2017-03-24 22:40:47serhiy.storchakasetmessages: +msg290260
2017-03-17 21:00:36larrysetpull_requests: +pull_request626
2017-03-08 15:20:37serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2017-03-05 21:38:08serhiy.storchakasetpull_requests: +pull_request397
2017-03-03 21:16:16terry.reedysetnosy: +terry.reedy
messages: +msg288930
2017-02-26 07:14:06serhiy.storchakasetmessages: +msg288589
2017-02-26 03:43:29ncoghlansetmessages: +msg288587
2017-02-25 22:50:54serhiy.storchakasetfiles: +webbrowser-delayed-initialization-2.patch

messages: +msg288585
2017-02-25 14:52:10ncoghlansetmessages: +msg288566
2017-02-25 11:55:16serhiy.storchakasetmessages: +msg288563
2017-02-25 11:48:58serhiy.storchakasetfiles: +webbrowser-delayed-initialization.patch
keywords: +patch
2017-02-25 11:47:58serhiy.storchakasetnosy: +ncoghlan

messages: +msg288562
stage: patch review
2017-02-25 11:38:23louielusetnosy: +louielu
messages: +msg288561
2017-02-25 09:26:58serhiy.storchakacreate
Supported byThe Python Software Foundation,
Powered byRoundup
Copyright © 1990-2022,Python Software Foundation
Legal Statements

[8]ページ先頭

©2009-2026 Movatter.jp