Syncing latest changes between public/private.

This commit is contained in:
Eric Froemling 2020-03-12 21:08:53 -07:00
parent 3c70c68257
commit 4ef4bc60cb
4 changed files with 32 additions and 16 deletions

View File

@ -1812,6 +1812,7 @@
<w>valnew</w> <w>valnew</w>
<w>vals</w> <w>vals</w>
<w>valuedispatch</w> <w>valuedispatch</w>
<w>valueerror</w>
<w>valuetext</w> <w>valuetext</w>
<w>valuetype</w> <w>valuetype</w>
<w>varargannotation</w> <w>varargannotation</w>

View File

@ -162,9 +162,13 @@ class AssetGather:
def fetch_url(url: str, filename: Path, asset_gather: AssetGather) -> None: def fetch_url(url: str, filename: Path, asset_gather: AssetGather) -> None:
"""Fetch a given url to a given filename.""" """Fetch a given url to a given filename for a given AssetGather.
"""
# pylint: disable=too-many-locals
import socket import socket
import threading
# We don't want to keep the provided AssetGather alive, but we want # We don't want to keep the provided AssetGather alive, but we want
# to abort if it dies. # to abort if it dies.
@ -173,31 +177,41 @@ def fetch_url(url: str, filename: Path, asset_gather: AssetGather) -> None:
# Pass a very short timeout to urllib so we have opportunities # Pass a very short timeout to urllib so we have opportunities
# to cancel even with network blockage. # to cancel even with network blockage.
ureq = urllib.request.urlopen(url, None, 1) req = urllib.request.urlopen(url, timeout=1)
file_size = int(ureq.headers["Content-Length"]) file_size = int(req.headers['Content-Length'])
print(f"\nDownloading: {filename} Bytes: {file_size:,}") print(f'\nDownloading: {filename} Bytes: {file_size:,}')
def doit() -> None:
time.sleep(1)
print('dir', type(req.fp), dir(req.fp))
print('WOULD DO IT', flush=True)
# req.close()
req.fp.close()
threading.Thread(target=doit).run()
with open(filename, 'wb') as outfile: with open(filename, 'wb') as outfile:
file_size_dl = 0 file_size_dl = 0
# I'm guessing we want this decently big so we're running fewer cycles block_sz = 1024 * 1024 * 1000
# of this loop during downloads and keeping our load lower. Our timeout
# should ensure a minimum rate for the loop and this will affect
# the maximum. Perhaps we should aim for a few cycles per second on
# an average connection?..
block_sz = 1024 * 1024
time_outs = 0 time_outs = 0
while True: while True:
try: try:
data = ureq.read(block_sz) data = req.read(block_sz)
except ValueError:
import traceback
traceback.print_exc()
print('VALUEERROR', flush=True)
break
except socket.timeout: except socket.timeout:
print('TIMEOUT', flush=True)
# File has not had activity in max seconds. # File has not had activity in max seconds.
if time_outs > 3: if time_outs > 3:
print("\n\n\nsorry -- try back later") print('\n\n\nsorry -- try back later')
os.unlink(filename) os.unlink(filename)
raise raise
print("\nHmmm... little issue... " print('\nHmmm... little issue... '
"I'll wait a couple of seconds") 'I\'ll wait a couple of seconds')
time.sleep(3) time.sleep(3)
time_outs += 1 time_outs += 1
continue continue

View File

@ -1,5 +1,5 @@
<!-- THIS FILE IS AUTO GENERATED; DO NOT EDIT BY HAND --> <!-- THIS FILE IS AUTO GENERATED; DO NOT EDIT BY HAND -->
<!--DOCSHASH=0ccb27f0a14c6ad6f07acd13b8bd2fbb--> <!--DOCSHASH=266725d2f42aff8a96924a30416d8926-->
<h4><em>last updated on 2020-03-12 for Ballistica version 1.5.0 build 20001</em></h4> <h4><em>last updated on 2020-03-12 for Ballistica version 1.5.0 build 20001</em></h4>
<p>This page documents the Python classes and functions in the 'ba' module, <p>This page documents the Python classes and functions in the 'ba' module,
which are the ones most relevant to modding in Ballistica. If you come across something you feel should be included here or could be better explained, please <a href="mailto:support@froemling.net">let me know</a>. Happy modding!</p> which are the ones most relevant to modding in Ballistica. If you come across something you feel should be included here or could be better explained, please <a href="mailto:support@froemling.net">let me know</a>. Happy modding!</p>

View File

@ -41,6 +41,7 @@ def test_assetmanager() -> None:
"""Testing.""" """Testing."""
with tempfile.TemporaryDirectory() as tmpdir: with tempfile.TemporaryDirectory() as tmpdir:
manager = AssetManager(rootdir=Path(tmpdir)) manager = AssetManager(rootdir=Path(tmpdir))
wref = weakref.ref(manager) wref = weakref.ref(manager)
manager.start() manager.start()
@ -52,7 +53,7 @@ def test_assetmanager() -> None:
manager.stop() manager.stop()
# Make sure nothing is keeping itself alive # Make sure nothing is keeping itself alive.
del manager del manager
del gather del gather
assert wref() is None assert wref() is None