Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
mio
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Anders Blomdell
mio
Commits
fa0c5866
Commit
fa0c5866
authored
2 years ago
by
Anders Blomdell
Browse files
Options
Downloads
Patches
Plain Diff
Improve urlgrabber_compat load balancing
parent
088ee574
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/mio/urlgrabber_compat.py
+16
-9
16 additions, 9 deletions
src/mio/urlgrabber_compat.py
with
16 additions
and
9 deletions
src/mio/urlgrabber_compat.py
+
16
−
9
View file @
fa0c5866
#!/usr/bin/python3
#
# Hackish compat library when urlgrabber is missing (MacOS)
#
try
:
# Python 3
from
urllib.request
import
urlopen
except
ImportError
:
# Python 2 fallback
from
urllib2
import
urlopen
import
urllib.parse
import
calendar
import
time
import
random
INFO_FILETIME
=
object
()
...
...
@@ -29,6 +27,7 @@ class CurlWrapper:
def
__getattr__
(
self
,
what
):
return
getattr
(
self
.
url
,
what
)
pass
class
Compat
:
...
...
@@ -40,15 +39,23 @@ class Compat:
class
MirrorGroup
:
def
__init__
(
self
,
grabber
,
urls
):
self
.
urls
=
urls
self
.
urls
=
list
(
urls
)
random
.
shuffle
(
self
.
urls
)
self
.
mru
=
dict
([
(
u
,
0
)
for
u
in
self
.
urls
])
def
urlopen
(
self
,
path
):
errors
=
[]
for
u
in
self
.
urls
:
for
u
in
reversed
(
sorted
(
self
.
urls
,
key
=
lambda
u
:
self
.
mru
[
u
]))
:
url
=
"
%s/%s
"
%
(
u
,
path
)
try
:
return
CurlWrapper
(
urlopen
(
url
))
# print(u, self.mru[u], path)
result
=
CurlWrapper
(
urlopen
(
url
))
self
.
mru
[
u
]
+=
1
return
result
except
IOError
as
e
:
# print(e.__class__, e)
# TODO, penalize umreachable hosts?
self
.
mru
[
u
]
/=
2
errors
.
append
((
url
,
e
))
pass
raise
IOError
(
"
Failed to get
'
%s
'
(%s)
"
%
(
path
,
errors
))
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment