Adrian Larson
Adrian Larson

Reputation: 370

Process Doesn't End When Closed

I built a web-scraper application with Python. It consists of three main parts:

  1. The GUI (built on tkinter)
  2. A Client (controls interface between front- and back-end)
  3. Back-end code (various threaded processes).

The problem I have is that when the user hits X to exit the program instead of quitting through the interface, it seems like root.destroy() never gets called and the application runs forever, even though the window does disappear. This ends up consuming vast amounts of system resources.

I have tried setting all threads to Daemon without much success. Is there any other reason the program would keep eating up CPU after exit?

Upvotes: 2

Views: 488

Answers (1)

Fredrick Brennan
Fredrick Brennan

Reputation: 7357

You don't want to set all threads to daemon. You want to set the client thread and the back-end thread to daemon. That way, when the GUI thread dies, the threads with daemon set to True end as well.

From the documentation:

A thread can be flagged as a “daemon thread”. The significance of this flag is that the entire Python program exits when only daemon threads are left.

Upvotes: 2

Related Questions