Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 429215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T19:45:11+00:00 2026-05-12T19:45:11+00:00

What would be the best way to handle lightweight crash recovery for my program?

  • 0

What would be the best way to handle lightweight crash recovery for my program?

I have a Python program that runs a number of test cases and the results are stored in a dictionary which serves as a cache. If I could save (and then restore) each item that is added to the dictionary, I could simply run the program again and the caching would provide suitable crash recovery.

  1. You may assume that the keys and values in the dictionary are easily convertible to strings ie. using either str or the pickle module.
  2. I want this to be completely cross platform – well at least as cross platform as Python is
  3. I don’t want to simply write out each value to a file and load it in my program might crash while I am writing the file
  4. UPDATE: This is intended to be a lightweight module so a DBMS is out of the question.
  5. UPDATE: Alex is correct in that I don’t actually need to protect against crashes while writing out, but there are circumstances where I would like to be able to manually terminate it in a recoverable state.
  6. UPDATE Added a highly limited solution using standard input below
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T19:45:12+00:00Added an answer on May 12, 2026 at 7:45 pm

    There’s no good way to guard against “your program crashing while writing a checkpoint to a file”, but why should you worry so much about that?! What ELSE is your program doing at that time BESIDES “saving checkpoint to a file”, that could easily cause it to crash?!

    It’s hard to beat pickle (or cPickle) for portability of serialization in Python, but, that’s just about “turning your keys and values to strings”. For saving key-value pairs (once stringified), few approaches are safer than just appending to a file (don’t pickle to files if your crashes are far, far more frequent than normal, as you suggest tjey are).

    If your environment is incredibly crash-prone for whatever reason (very cheap HW?-), just make sure you close the file (and fflush if the OS is also crash-prone;-), then reopen it for append. This way, worst that can happen is that the very latest append will be incomplete (due to a crash in the middle of things) — then you just catch the exception raised by unpickling that incomplete record and redo only the things that weren’t saved (because they weren’t completed due to a crash, OR because they were completed but not fully saved due to a crash, comes to much the same thing in the end).

    If you have the option of checkpointing to a database engine (instead of just doing so to files), consider it seriously! The DB engine will keep transaction logs and ensure ACID properties, making your application-side programming much easier IF you can count on that!-)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What would be the best way to handle ColdFusion Cookies from a javascript function?
I would like to understand whats the best way to handle exceptions in Multicast
What do you think would be the best way to handle no network connectivity?
I am curious what would be the best way to handle an ambiguous date
What would be the best way to handle the __repr__() function for an object
I was wondering what would be the best way to handle errors in an
When malloc() fails, which would be the best way to handle the error? If
Was wondering what the best way to handle an expensive web task? I have
what would be best way to handle simple text styles like bbcode allowing bold
I wonder since a long time what would be the best way to handle

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.