@@ -77,6 +77,9 @@ def wait_for(condition: Callable[..., bool]) -> bool:
7777    return  condition ()
7878
7979
80+ _NOT_EXITED_STATUSES  =  {"running" , "created" }
81+ 
82+ 
8083def  wait_for_logs (
8184    container : "DockerContainer" ,
8285    predicate : Union [Callable , str ],
@@ -103,11 +106,13 @@ def wait_for_logs(
103106    """ 
104107    if  isinstance (predicate , str ):
105108        predicate  =  re .compile (predicate , re .MULTILINE ).search 
109+     wrapped  =  container .get_wrapped_container ()
106110    start  =  time .time ()
107111    while  True :
108112        duration  =  time .time () -  start 
109-         stdout  =  container .get_logs ()[0 ].decode ()
110-         stderr  =  container .get_logs ()[1 ].decode ()
113+         stdout , stderr  =  container .get_logs ()
114+         stdout  =  stdout .decode ()
115+         stderr  =  stderr .decode ()
111116        predicate_result  =  (
112117            predicate (stdout ) or  predicate (stderr )
113118            if  predicate_streams_and  is  False 
@@ -118,6 +123,8 @@ def wait_for_logs(
118123            return  duration 
119124        if  duration  >  timeout :
120125            raise  TimeoutError (f"Container did not emit logs satisfying predicate in { timeout :.3f}   "seconds" )
121-         if  raise_on_exit  and  container .get_wrapped_container ().status  !=  "running" :
122-             raise  RuntimeError ("Container exited before emitting logs satisfying predicate" )
126+         if  raise_on_exit :
127+             wrapped .reload ()
128+             if  wrapped .status  not  in _NOT_EXITED_STATUSES :
129+                 raise  RuntimeError ("Container exited before emitting logs satisfying predicate" )
123130        time .sleep (interval )
0 commit comments