[GitHub] KellenSunderland commented on a change in pull request #9671: Exp backoff for downloads.

2018-02-02 Thread GitBox
KellenSunderland commented on a change in pull request #9671: Exp backoff for 
downloads.
URL: https://github.com/apache/incubator-mxnet/pull/9671#discussion_r165642736
 
 

 ##
 File path: python/mxnet/gluon/utils.py
 ##
 @@ -61,13 +52,13 @@ def split_data(data, num_slice, batch_axis=0, 
even_split=True):
 size = data.shape[batch_axis]
 if size < num_slice:
 raise ValueError(
-"Too many slices for data with shape %s. Arguments are " \
-"num_slice=%d and batch_axis=%d."%(str(data.shape), num_slice, 
batch_axis))
+"Too many slices for data with shape %s. Arguments are "
 
 Review comment:
   I think triplequotes would be the equiv of
   
   ```python
   "Too many slices for data with shape %s. Arguments are \n" \
   "num_slice=%d and batch_axis=%d."%(str(data.shape), num_slice, batch_axis))
   ```
   
   but I'll try a few options.


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] KellenSunderland commented on a change in pull request #9671: Exp backoff for downloads.

2018-02-02 Thread GitBox
KellenSunderland commented on a change in pull request #9671: Exp backoff for 
downloads.
URL: https://github.com/apache/incubator-mxnet/pull/9671#discussion_r165642736
 
 

 ##
 File path: python/mxnet/gluon/utils.py
 ##
 @@ -61,13 +52,13 @@ def split_data(data, num_slice, batch_axis=0, 
even_split=True):
 size = data.shape[batch_axis]
 if size < num_slice:
 raise ValueError(
-"Too many slices for data with shape %s. Arguments are " \
-"num_slice=%d and batch_axis=%d."%(str(data.shape), num_slice, 
batch_axis))
+"Too many slices for data with shape %s. Arguments are "
 
 Review comment:
   I think triplequotes would be the equiv of
   
   ```
   "Too many slices for data with shape %s. Arguments are \n" \
   "num_slice=%d and batch_axis=%d."%(str(data.shape), num_slice, batch_axis))
   ```
   
   but I'll try a few options.


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] KellenSunderland commented on a change in pull request #9671: Exp backoff for downloads.

2018-02-01 Thread GitBox
KellenSunderland commented on a change in pull request #9671: Exp backoff for 
downloads.
URL: https://github.com/apache/incubator-mxnet/pull/9671#discussion_r165446394
 
 

 ##
 File path: python/mxnet/utils.py
 ##
 @@ -0,0 +1,151 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""Utility functions applicable to all areas of code (tests, tutorials, gluon, 
etc)."""
+
+__all__ = ['check_sha1', 'download', 'create_dir']
+
+import errno
+import logging
+import time
+import os
+import hashlib
+
+try:
+import requests
+except ImportError:
+class requests_failed_to_import(object):
+pass
+requests = requests_failed_to_import
+
+
+def check_sha1(filename, sha1_hash):
+"""Check whether the sha1 hash of the file content matches the expected 
hash.
+
+Parameters
+--
+filename : str
+Path to the file.
+sha1_hash : str
+Expected sha1 hash in hexadecimal digits.
+
+Returns
+---
+bool
+Whether the file content matches the expected hash.
+"""
+sha1 = hashlib.sha1()
+with open(filename, 'rb') as f:
+while True:
+data = f.read(1048576)
+if not data:
+break
+sha1.update(data)
+
+return sha1.hexdigest() == sha1_hash
+
+
+def _download_retry_with_backoff(fname, url, max_attempts=4):
+"""Downloads a url with backoff applied, automatically re-requesting after 
a failure.
 
 Review comment:
   This requires using a session right?  I'm not sure if that then lets us 
stream to a file.  I'll check it out though.  I'd prefer to use built in 
functionality provided we get backoff and streaming support.


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services