You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2019/01/14 09:45:04 UTC

[GitHub] ashb commented on a change in pull request #4516: [AIRFLOW-2524] Handle StopIteration in CloudWatch logs retrieval

ashb commented on a change in pull request #4516: [AIRFLOW-2524] Handle StopIteration in CloudWatch logs retrieval
URL: https://github.com/apache/airflow/pull/4516#discussion_r247428826
 
 

 ##########
 File path: airflow/contrib/hooks/sagemaker_hook.py
 ##########
 @@ -304,7 +304,15 @@ def multi_stream_iter(self, log_group, streams, positions=None):
         positions = positions or {s: Position(timestamp=0, skip=0) for s in streams}
         event_iters = [self.log_stream(log_group, s, positions[s].timestamp, positions[s].skip)
                        for s in streams]
-        events = [next(s) if s else None for s in event_iters]
+        events = []
+        for s in event_iters:
+            if not s:
+                events.append(None)
+                continue
+            try:
+                events.append(next(s))
+            except StopIteration:
+                events.append(None)
 
 Review comment:
   This seems.... odd to me. StopIteration inside a `for` loop should already be handled:
   
   
   ```python
   def mkiter():
       yield 1
       yield 2
       yield 3
       raise StopIteration()
   
   for a in mkiter():
       print(a)
   print("done")
   ```
   
   When run:
   
   ```python
   >>> def mkiter():
   ...     yield 1
   ...     yield 2
   ...     yield 3
   ...     raise StopIteration()
   ...
   >>> mkiter()
   <generator object mkiter at 0x10b9d9308>
   >>> for a in mkiter():
   ...     print(a)
   ...
   1
   2
   3
   >>> print("done")
   done
   ```

----------------------------------------------------------------
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