Code Room
Code reviewHardcr-g430
Subject DeadlocksLevel Senior–Staff~30 minCommon in Concurrency interviewsIndustries Software development

Question

Review this Python graph engine. Each node has its own lock; an edge update locks both endpoints.

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.

Talk through your review
Code to reviewpython
class Node:    def __init__(self, name):        self.name = name        self.lock = threading.Lock()        self.edges = {} def add_edge(a: Node, b: Node, weight):    with a.lock:        with b.lock:            a.edges[b.name] = weight            b.edges[a.name] = weight
Run or narrate your approach, then ask the coach.