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.
Saved automatically
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.
Related Questions in Python Programming
Explain Python GIL (Global Interpreter Lock) and how to bypass it for CPU-bound tasks
Advanced level • 311 views
What is the Python Global Interpreter Lock (GIL), how does it impact multi-threaded CPU-bound programs, and what are the workarounds in Python 3.12+?
Intermediate level • 151 views
When would you use a list, tuple, set, or dictionary in Python?
Easy level • 3 views
Explain the difference between Python's GIL (Global Interpreter Lock) and multi-threading vs multi-processing.
Advanced level • 2 views
What is RAII (Resource Acquisition Is Initialization) in C++ and how do smart pointers (unique_ptr, shared_ptr, weak_ptr) prevent memory leaks?
Intermediate level • 2 views