Skip to Content
Modern Python Standard Library Cookbook
book

Modern Python Standard Library Cookbook

by Alessandro Molina
August 2018
Intermediate to advanced
366 pages
10h 14m
English
Packt Publishing
Content preview from Modern Python Standard Library Cookbook

Safely replacing file's content

Replacing the content of a file is a very slow operation. Compared to replacing the content of a variable, it's usually a few times slower; when we write something to disk, it takes time before it's actually flushed and time before the content is actually written to disk. It's not an atomic operation, so if our software faces any issues while saving a file, there is a good chance that the file might end up being half-written and our users don't have a way to recover the consistent state of their data.

There is a pattern commonly used to solve this kind of issue, which is based on the fact that writing a file is a slow, expensive, error-prone operation, but renaming a file is an atomic, fast, and cheap operation. ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Advanced Python Development: Using Powerful Language Features in Real-World Applications

Advanced Python Development: Using Powerful Language Features in Real-World Applications

Matthew Wilkes

Publisher Resources

ISBN: 9781788830829Supplemental Content