未验证 提交 d24a2ff0 编写于 作者: W wuzewu 提交者: GitHub

add timeout when request for resource_list

......@@ -140,6 +140,9 @@ class ConvertCommand(BaseCommand):
self.module = args.module_name
self.version = args.module_version if args.module_version is not None else '1.0.0'
self.src = args.model_dir
if not os.path.isdir(self.src):
print('`{}` is not exists or not a directory path'.format(self.src))
return False
self.dest = args.output_dir if args.output_dir is not None else os.path.join(
'{}_{}'.format(self.module, str(time.time())))
......
......@@ -250,9 +250,15 @@ class HubServer(object):
if not os.path.exists(CACHE_HOME):
utils.mkdir(CACHE_HOME)
try:
r = requests.get(self.get_server_url() + '/' + 'search')
data = json.loads(r.text)
cache_path = os.path.join(CACHE_HOME, RESOURCE_LIST_FILE)
if os.path.exists(cache_path):
r = requests.get(
self.get_server_url() + '/' + 'search', timeout=0.5)
else:
r = requests.get(
self.get_server_url() + '/' + 'search', timeout=8)
data = json.loads(r.text)
with open(cache_path, 'w+') as fp:
yaml.safe_dump({'resource_list': data['data']}, fp)
return True
......
......@@ -13,5 +13,5 @@
# See the License for the specific language governing permissions and
# limitations under the License.
""" PaddleHub version string """
hub_version = "1.8.1"
hub_version = "1.8.3"
module_proto_version = "1.0.0"
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册