Verified Jobs Live
Python Programming Medium Level ~3 min read

How would you make a file-processing script recover safely after interruption?

Interactive Practice Mode
Formulate your thoughts or take notes before revealing the model solution.
Model Answer & Deep-Dive Explanation

Process input in identifiable batches and record a checkpoint only after the corresponding output is durable. Write replacement files to a temporary file on the same filesystem, flush as required, and use an appropriate atomic rename or replace operation. Include enough input identity to detect a changed source before resuming. Make repeated batch processing idempotent, log failures with row context, and separate bad records from transient errors. Test interruption before and after checkpoint updates. Atomic replacement protects a file boundary; it does not by itself make multiple files a transaction.