Commit d0f83664 by sf-wind Committed by Lianmin Zheng

Avoid runtime exception when file doesn't exist (#2441)

* Avoid runtime exception when file doesn't exist

* Update the check based on feedback

* Revert the old fix
parent 2a871f35
......@@ -77,7 +77,8 @@ def context(target, extra_files=None):
for name in possible_names:
name = _alias(name)
if name in all_packages:
check_backend(name)
if not check_backend(name):
continue
filename = "%s_%s.log" % (name, PACKAGE_VERSION[name])
best_context.load(os.path.join(AUTOTVM_TOPHUB_ROOT_PATH, filename))
......@@ -98,6 +99,11 @@ def check_backend(backend):
----------
backend: str
The name of backend.
Returns
----------
success: bool
Whether the check is successful.
"""
backend = _alias(backend)
assert backend in PACKAGE_VERSION, 'Cannot find backend "%s" in TopHub' % backend
......@@ -105,7 +111,7 @@ def check_backend(backend):
version = PACKAGE_VERSION[backend]
package_name = "%s_%s.log" % (backend, version)
if os.path.isfile(os.path.join(AUTOTVM_TOPHUB_ROOT_PATH, package_name)):
return
return True
if sys.version_info >= (3,):
import urllib.request as urllib2
......@@ -113,8 +119,10 @@ def check_backend(backend):
import urllib2
try:
download_package(package_name)
return True
except urllib2.URLError as e:
logging.warning("Failed to download tophub package for %s: %s", backend, e)
return False
def download_package(package_name):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment