File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -982,6 +982,7 @@ def __init__(
982982 'Use the SingleThreadedExecutor instead.' )
983983 self ._futures : List [Future [Any ]] = []
984984 self ._executor = ThreadPoolExecutor (num_threads )
985+ self ._futures_lock = Lock ()
985986
986987 def _spin_once_impl (
987988 self ,
@@ -1002,12 +1003,11 @@ def _spin_once_impl(
10021003 else :
10031004 self ._executor .submit (handler )
10041005 self ._futures .append (handler )
1005- # make a copy of the list that we iterate over while modifying it
1006- # (https://stackoverflow.com/q/1207406/3753684)
1007- for future in self ._futures [:]:
1008- if future .done ():
1009- self ._futures .remove (future )
1010- future .result () # raise any exceptions
1006+ with self ._futures_lock :
1007+ for future in self ._futures :
1008+ if future .done ():
1009+ self ._futures .remove (future )
1010+ future .result () # raise any exceptions
10111011
10121012 def spin_once (self , timeout_sec : Optional [float ] = None ) -> None :
10131013 self ._spin_once_impl (timeout_sec )
You can’t perform that action at this time.
0 commit comments