Unverified Commit 48cf1e41 authored by 陈序's avatar 陈序 Committed by GitHub
Browse files

fix: deque mutated during iteration in abort_seq_group (#2371)

parent 97460585
...@@ -104,21 +104,24 @@ class Scheduler: ...@@ -104,21 +104,24 @@ class Scheduler:
request_id = (request_id, ) request_id = (request_id, )
request_ids = set(request_id) request_ids = set(request_id)
for state_queue in [self.waiting, self.running, self.swapped]: for state_queue in [self.waiting, self.running, self.swapped]:
# We need to reverse the list as we are removing elements aborted_groups = []
# from it as we iterate over it. If we don't do it, for seq_group in state_queue:
# indices will get messed up and we will skip over elements. if not request_ids:
for seq_group in reversed(state_queue): # Using 'break' here may add two extra iterations,
# but is acceptable to reduce complexity .
break
if seq_group.request_id in request_ids: if seq_group.request_id in request_ids:
# Remove the sequence group from the state queue. # Appending aborted group into pending list.
state_queue.remove(seq_group) aborted_groups.append(seq_group)
for seq in seq_group.get_seqs():
if seq.is_finished():
continue
seq.status = SequenceStatus.FINISHED_ABORTED
self.free_seq(seq)
request_ids.remove(seq_group.request_id) request_ids.remove(seq_group.request_id)
if not request_ids: for aborted_group in aborted_groups:
return # Remove the sequence group from the state queue.
state_queue.remove(aborted_group)
for seq in seq_group.get_seqs():
if seq.is_finished():
continue
seq.status = SequenceStatus.FINISHED_ABORTED
self.free_seq(seq)
def has_unfinished_seqs(self) -> bool: def has_unfinished_seqs(self) -> bool:
return self.waiting or self.running or self.swapped return self.waiting or self.running or self.swapped
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment