@@ -380,6 +380,18 @@ def wait_for_event(self, filter=None, timeout=None):
380380 )
381381 return None
382382
383+ def wait_for_events (self , events , timeout = None ):
384+ """Wait for a list of events in `events` in any order.
385+ Return the events not hit before the timeout expired"""
386+ events = events [:] # Make a copy to avoid modifying the input
387+ end_time = time .time () + timeout if timeout else None
388+ while events and (not end_time or end_time > time .time ()):
389+ event_dict = self .wait_for_event (filter = events , timeout = timeout )
390+ if not event_dict :
391+ continue
392+ events .remove (event_dict ["event" ])
393+ return events
394+
383395 def wait_for_stopped (self , timeout = None ):
384396 stopped_events = []
385397 stopped_event = self .wait_for_event (
@@ -621,9 +633,7 @@ def request_attach(
621633 response = self .send_recv (command_dict )
622634
623635 if response ["success" ]:
624- # Wait for a 'process' and 'initialized' event in any order
625- self .wait_for_event (filter = ["process" , "initialized" ])
626- self .wait_for_event (filter = ["process" , "initialized" ])
636+ self .wait_for_events (["process" , "initialized" ])
627637 return response
628638
629639 def request_breakpointLocations (
@@ -878,9 +888,7 @@ def request_launch(
878888 response = self .send_recv (command_dict )
879889
880890 if response ["success" ]:
881- # Wait for a 'process' and 'initialized' event in any order
882- self .wait_for_event (filter = ["process" , "initialized" ])
883- self .wait_for_event (filter = ["process" , "initialized" ])
891+ self .wait_for_events (["process" , "initialized" ])
884892 return response
885893
886894 def request_next (self , threadId , granularity = "statement" ):
0 commit comments