Code Room
Code reviewHardcr-g233
Subject Race conditionsLevel Senior–Staff~40 minCommon in Storage & CDN · Concurrency interviewsIndustries Software development

Question

Review this Python routine that writes a file only if it doesn't already exist.

Under concurrent callers (threads or processes), what breaks?

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
import os def write_once(path, data):    if not os.path.exists(path):      # (1) check        with open(path, 'w') as f:    # (2) use            f.write(data)        return True    return False                       # already existed
Run or narrate your approach, then ask the coach.