You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2018/11/27 21:19:05 UTC

[GitHub] zhreshold commented on a change in pull request #13209: Allow dataloader iterator to be reused

zhreshold commented on a change in pull request #13209: Allow dataloader iterator to be reused
URL: https://github.com/apache/incubator-mxnet/pull/13209#discussion_r236850053
 
 

 ##########
 File path: python/mxnet/gluon/data/dataloader.py
 ##########
 @@ -267,20 +316,128 @@ def __next__(self):
                 return batch
 
     def next(self):
+        """Compatible portal for __next__ in python2.
+
+        Returns
+        -------
+        type
+            Description of returned object.
+
+        """
         return self.__next__()
 
     def __iter__(self):
+        """Requiring iterator will reset current instance, but keep all workers
+        alive, thus save re-init time of forking processes.
+
+        Returns
+        -------
+        iterator
+            Iterator of self.
+
+        """
+        self._reset()
         return self
 
 Review comment:
   iterators from the same dataloader are two separate instances, they don't interfere with each other, however, for explicitly cached iterator, it will break
   
   ```
   a = [1,2,3]
   it = iter(a)
   for x in it:
       for y in it:
           # this will not work

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services