Lo-Fi Python

Jan 05, 2022

How to Track Python Script Completion

Did your script run to completion? Sure, you might log some tracebacks along the way or terminate the program early with sys.exit(). But did your script actually run completely to the end? I have yet to use the Trace module but it seems worth checking out also. Visualization tools like heartrate are worth mentioning too depending on how you are running your scripts. Task runners typically have run status tracking as well. I like having a visual confirmation by logging some sort of information when a script finishes as intended. It's nice to know when your scripts finished or not. Use logging and Trace to up your reliability of your scripts.

An easy way to track this is with the logging module:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
import logging

def improvise():
    """Improv Tutorial: https://www.youtube.com/watch?v=C6wY9OwqJ2A"""
    try:
        print("Boom! Detective Michael Scarn, I'm with the FBI!")
        return None
    except:
        logging.exception("Error occurred during improv.")
        return None

FORMAT = '%(asctime)s %(clientip)-15s %(user)-8s %(message)s'
logging.basicConfig(filename="improvise.log", format=FORMAT)
improvise()
logging.info("Improvisation finished!")