0

I've an instagram bot with GUI's. There is two class with different .py files. I start the functions with GUI's with no problem but since the functions takes long time and until not completed GUI's are freezing. Therefore i cannot click the stop button thats my problem. I tried using threads it leads to not freezing but i cannot stop it. Therefore i need help I return the beginning. What is the easiest way to prevent freezing?

These are brief GUI's code

def send_requests(self):
    username = self.username_entry2.get()
    self.bot.send_requests_following(username)

def stop_bot(self):
    self.bot.stop()
if __name__ == '__main__':
    root = tk.Tk()
    app = App(root)
    root.protocol("WM_DELETE_WINDOW", app.on_closing)
    root.mainloop()
    root.destroy()

This is my bot function on other class.

    def send_requests_following(self,profile):

I really don't know what to do. Thank you.

1 Answers1

-1

You could try adding a loop then creating an instance of thread.Events(). Adding a is_set() and if it’s true break the loop. Using .set() to terminate the thread by setting is_set() to true. Another approach is using the multiprocessing module. Then using .terminate() to stop the thread.

Darkshadogt
  • 49
  • 1
  • 5