I have a python program which takes several minutes to finish. I have some debugging code which is printed only when a variable is set. the variable is set through command line or environment variable in my current implementation. I want to enable/disable debugging on the fly when program is executing.
For example, consider following code:
import time
import os
debugging=False
if "DEBUG" in os.environ:
debugging = True
def debug():
if debugging:
print("debug statement");
def enable_debugging():
global debugging
debugging = True
def disable_debugging():
global debugging
debugging = False
print("1")
debug()
time.sleep(20)
print("2")
debug()
So while the program is executing with debugging off, how can I dynamically enable debugging while the program is executing? In other words, how can I execute function enable_debugging
(maybe in a separate thread), when a particular string is inputted?