I have a script that uses a global object (from selenium, driver=Webdriver.Firefox()) repeatedly. But at some point when the script is waiting too long for page to load (in the middle of an operation) the script is then rebooting, relaunching the script and continuing from the same spot, as in:
def do_web_stuff():
"script stuff going on"
if "page takes too long":
reboot "closes firefox browser", "run script from when stopped"
"continue"
if __name__ == "__main__":
driver = webdriver.Firefox()
My problem is when i reboot, driver in no longer active there for if i reboot the script I get error 111 "Connection refused" which is understandable. If i relaunch driver in the reboot section i get NameError: global name 'driver' is not defined.
I've thought about making driver global in the reboot function but then i get a SyntaxError: "is local and global". So, hmmm, what to do? I would really prefer the object to be in the global scope instead of passing it from one function to the other.
What would be an good practice in this situation?