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 6007755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:43:39+00:00 2026-05-23T01:43:39+00:00

I wrote Python script that processes big number of large text files and may

  • 0

I wrote Python script that processes big number of large text files and may run a lot of time. Sometimes, there is a need to stop the running script and to resume it later. The possible reasons to stop the script are program crash, disk ‘out of space’ situation or many others when you have to do it. I want to implement kind of “stop/resume” mechanism for the script.

  • On stop: the script quits & saves its current state.
  • On resume: the script starts, but continues from the latest saved state

I’m going to implement it using the pickle and the signal modules.

I’ll be glad to hear how to do it in pythonic way.

Thank you!

  • 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-23T01:43:40+00:00Added an answer on May 23, 2026 at 1:43 am

    Here is something simple that hopefully can help you:

    import time
    import pickle
    
    
    REGISTRY = None
    
    
    def main(start=0):
        """Do some heavy work ..."""
    
        global REGISTRY
    
        a = start
        while 1:
            time.sleep(1)
            a += 1
            print a
            REGISTRY = pickle.dumps(a)
    
    
    if __name__ == '__main__':
        print "To stop the script execution type CTRL-C"
        while 1:
           start = pickle.loads(REGISTRY) if REGISTRY else 0
            try:
                main(start=start)
            except KeyboardInterrupt:
                resume = raw_input('If you want to continue type the letter c:')
                if resume != 'c':
                    break
    

    Example of running:

    $ python test.py
    To stop the script execution type CTRL-C
    1
    2
    3
    ^CIf you want to continue type the letter c:c
    4
    5
    6
    7
    8
    9
    ^CIf you want to continue type the letter c:
    $ python test.py
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Python script I recently wrote that I call using the command
I wrote a script in Python 2.6.2 that scans a directory for SVG's and
I wrote a python script that rotates an image 90 degrees. I am including
I wrote a python script that: 1. submits search queries 2. waits for the
I'm trying to write a python script that packages our software. This script needs
Greetings. I have written a little python script that calls MySQL in a subprocess.
I wrote this simple code in python to calculate a given number of primes.
I wrote a simple Python script to download a web page for offline viewing.
In the process of trying to write a Python script that uses PIL today,
I am trying to write a python script to process image files into shapefiles

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.