SaveScreenshot and Terminal issue

So I wrote a python script to automate some basic postprocessing functions that I would like to run in pvpython or pvbatch. I am able to use the run script button in the python shell within the GUI but would like to run this script solely from the terminal. Whenever I attempt to do so the exec attempts to run, but never finishes. In order to avoid overheating my computer, I have to force quit. I narrowed it down and realized the error is in the second to last line of code when I attempt to use the SavesScreenshot command. For some reason the script runs fine in pvpython if this line is commented out. Any ideas on where my issue may be stemming from?

@JDecker ,

Please share scripts and data

Best,

Here’s the error I get after I terminate the process. The script will be attached below.

CSV_Update_3.1.py (25.5 KB)

Please try to isolate the issue in less lines.

Also you did not share the data.