adding finalize and guard clauses against running python code after interpreter is finalized