I'm trying to implement a checkpoint mechanism for my original script with the following structure:
import os
import sys
from dotenv import load_dotenv
def main():
load_dotenv()
checkpoint = int(os.getenv('CHECKPOINT'))
if checkpoint == 0:
...
do something
...
checkpoint += 1
os.environ['CHECKPOINT'] = str(checkpoint)
checkpoint = int(os.getenv('CHECKPOINT'))
if checkpoint >= 1:
...
do something
...
checkpoint += 1
os.environ['CHECKPOINT'] = str(checkpoint)
My .env file
CHECKPOINT=0
While this method is working inside a Windows machine (localhost), it is not working on my Ubuntu server.
That is, if my code fails somewhere on the checkpoint 2, I should be able to rerun it from that point only.
For example, if code fails at checkpoint=2:
Windows machine:
checkpoint=2
Ubuntu machine:
checkpoint=0
Also, I am using try and except to catch failures from the code, then exit system if there is any using:
sys.exit()
I can use a config.json to set these from time to time, but I really wanted to know why this is happening.