-1

my code is mainly scraping pages by clicking next button. I wanted to add a button, when scraping continuously runs having possibility to stop it and exit running the main thread. - just stop program execution. I learnt from this SO better to run thread asynchronously then I would have a possibility to stop of execution and exit scraping in any moment. threading added one fine thing that close button does not freeze any more when code is running in the background. But when I click to stop it, the screen of GUI freezes and in background code runs...

main module;

...from tk_class_wdgs import *...
def start_app():
    create_sheets()
    def starting_scraping():
        conn(search_var[0])

    t=threading.Thread(target=starting_scraping)
    t.start()

if __name__=='__main__':
    tk_wdg=ClassWidgets()
    tk_wdg.btnS['command']=start_app
    tk_wdg.btnC['command']=sys.exit
    tk_wdg.root.mainloop()

tk_class_wdgs module;

import sys
from tkinter import *

class ClassWidgets():
    def __init__(self):
        self.root=Tk()
        self.frm01=Frame(master=self.root,width=10,height=10,borderwidth=3,bg='red')
        self.frm01.pack(expand='YES',fill=BOTH)
        self.frm02=Frame(master=self.root,width=10,height=10,borderwidth=3,bg='blue')
        self.frm02.pack(expand='YES',fill=BOTH)
        self.btnC=Button(master=self.frm02,text='close',bg='yellow')
        self.btnC.pack(expand='YES',side='right')
        self.btnS=Button(master=self.frm02,text='scrape',foreground='green')
        self.btnS.pack(expand='YES',side='left')
        self.ent=Entry(master=self.frm01)
        self.ent.pack(expand='YES',side='top',fill=X,padx=5,pady=5)


if __name__=='__main__':
    tkinter_widgets=ClassWidgets()
    tkinter_widgets.root.title('scraper')
    tkinter_widgets.btnC['command']=sys.exit
    tkinter_widgets.root.mainloop()
xlmaster
  • 659
  • 7
  • 23

1 Answers1

0

I added new function, named close_app

def close_app():
    driver.quit()
    tk_wdg.root.quit()
    sys.exit()


if __name__=='__main__':
    tk_wdg=ClassWidgets()
    tk_wdg.btnS['command']=start_app
    tk_wdg.btnC['command']=close_app
    tk_wdg.root.mainloop()

first I quit driver, which is global variable, then I quit mainloop, then added also sys.exit(). Adding at first line sys.exit() freezes the screen, and on background loop runs. Don't know why finishes everytime with such error'

raise TimeoutException(message, screen, stacktrace) selenium.common.exceptions.TimeoutException: Message: Stacktrace: Backtrace:

xlmaster
  • 659
  • 7
  • 23