Repeated sort in task scheduler
Review this Python scheduler loop.
What a strong answer looks like
Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix, specific and kind.
0:00 of about 30 min
Mark a line and say what kind of problem it is.0 findings
1def run_tasks(tasks):
2 # tasks: list of (priority, job); lower priority runs first
3 results = []
4 while tasks:
5 tasks.sort(key=lambda t: t[0]) # find next task
6 priority, job = tasks.pop(0)
7 results.append(execute(job))
8 tasks.extend(spawn_children(job)) # jobs can enqueue more jobs
9 return results
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.
Run or narrate your approach, then ask the coach.