-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_live_updates.py
More file actions
54 lines (41 loc) · 1.36 KB
/
Copy pathexample_live_updates.py
File metadata and controls
54 lines (41 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import asyncio
import sys
from mrdl import DownloadConfig, Downloader
async def main():
mirrors = [
"https://cofractal-ewr.mm.fcix.net/ubuntu-releases/",
"https://ohioix.mm.fcix.net/ubuntu-releases/",
"https://gigsouth.mm.fcix.net/ubuntu-releases/"
]
filename = "ubuntu-26.04-live-server-amd64.iso"
paths = [item + f"26.04/{filename}" for item in mirrors]
expected_hash = "sha256:dec49008a71f6098d0bcfc822021f4d042d5f2db279e4d75bdd981304f1ca5d9"
print("Starting download with dynamic speed limit updates...")
config = DownloadConfig(
urls=paths,
filename=filename,
threads_per_mirror=2,
chunk_size=1024 * 1024,
min_speed_kbps=100,
checksum=expected_hash
)
downloader = Downloader(config)
# Run download in a background task
task = asyncio.create_task(downloader.start())
try:
await asyncio.sleep(5)
downloader.set_speed_limit(1024)
await asyncio.sleep(15)
downloader.set_speed_limit(5120)
await asyncio.sleep(15)
downloader.set_speed_limit(None)
await task
except asyncio.CancelledError:
downloader.stop()
await task
if __name__ == "__main__":
try:
asyncio.run(main())
except KeyboardInterrupt:
sys.stdout.write("\r\033[K")
sys.stdout.flush()