diff --git a/paddlehub/common/hub_server.py b/paddlehub/common/hub_server.py index 4b7841c0a9c36c8e55822bd711377cea477f4f65..96e76cccda6c60491e6585c9350baf470efac949 100644 --- a/paddlehub/common/hub_server.py +++ b/paddlehub/common/hub_server.py @@ -283,17 +283,23 @@ class CacheUpdater(threading.Thread): api_url = srv_utils.uri_path(default_hub_server.get_server_url(), 'search') cache_path = os.path.join(CACHE_HOME, RESOURCE_LIST_FILE) - extra = { - "command": "update_cache", - "mtime": os.stat(cache_path).st_mtime - } + if os.path.exists(cache_path): + extra = { + "command": "update_cache", + "mtime": os.stat(cache_path).st_mtime + } + else: + extra = { + "command": "update_cache", + "mtime": time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + } try: r = srv_utils.hub_request(api_url, payload, extra) + if r.get("update_cache", 0) == 1: + with open(cache_path, 'w+') as fp: + yaml.safe_dump({'resource_list': r['data']}, fp) except Exception as err: pass - if r.get("update_cache", 0) == 1: - with open(cache_path, 'w+') as fp: - yaml.safe_dump({'resource_list': r['data']}, fp) def run(self): self.update_resource_list_file(self.module, self.version)