Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #78135 > unrolled thread

How to not enable a user to close the root tkinter window

Started byNicholas Cannon <nicholascannon1@gmail.com>
First post2014-09-22 04:43 -0700
Last post2014-09-23 15:54 +1000
Articles 4 — 2 participants

Back to article view | Back to comp.lang.python


Contents

  How to not enable a user to close the root tkinter window Nicholas Cannon <nicholascannon1@gmail.com> - 2014-09-22 04:43 -0700
    Re: How to not enable a user to close the root tkinter window Chris Angelico <rosuav@gmail.com> - 2014-09-22 21:56 +1000
    Re: How to not enable a user to close the root tkinter window Nicholas Cannon <nicholascannon1@gmail.com> - 2014-09-22 22:49 -0700
      Re: How to not enable a user to close the root tkinter window Chris Angelico <rosuav@gmail.com> - 2014-09-23 15:54 +1000

#78135 — How to not enable a user to close the root tkinter window

FromNicholas Cannon <nicholascannon1@gmail.com>
Date2014-09-22 04:43 -0700
SubjectHow to not enable a user to close the root tkinter window
Message-ID<6dffdfb3-82b3-4746-8f39-d6bfa727f439@googlegroups.com>
I have a project I am working on(https://github.com/nicodasiko/Article-Grab) which grabs info from the internet then displays it on the screen. It is a multithreaded program so as the function that retrieves the data from the internet there is also another function running in parallel which updates a ttk loading bar. Pretty simple multi threaded stuff. But I found out that the user can close the window whilst the threads are running which generates an error and is not healthy. Is there a way I can make the root tkinter window not close whilst the threads are running. I did this with the search bar and search button. Or can I safely stop the running threads and make them drop everything error free? Any help will be apreciated!

[toc] | [next] | [standalone]


#78137

FromChris Angelico <rosuav@gmail.com>
Date2014-09-22 21:56 +1000
Message-ID<mailman.14194.1411387007.18130.python-list@python.org>
In reply to#78135
On Mon, Sep 22, 2014 at 9:43 PM, Nicholas Cannon
<nicholascannon1@gmail.com> wrote:
> Or can I safely stop the running threads and make them drop everything error free?

This would be what I'd recommend. If someone wants to close your
program, s/he should be allowed to - imagine if internet traffic is
costly [1] and the query was done accidentally. So what you need is to
have the shutdown divided into three steps:

1) Close the window, or at least show visually that it's shutting down.
2) Send a signal to the worker threads
3) When the worker threads all shut down, terminate the program.

You can handle step 3 simply by ensuring that the threads aren't
marked as daemons. Python won't shut down until they're all gone. Step
1 is, I suspect, already happening. So all you need to do is message
the worker thread - and that can be done simply by setting a global
variable or something.

However, I'm not seeing any use of threads in your code. What thread
is being cut off? What's the error you're seeing?

ChrisA

[1] "costly" might not mean money, although it can. But imagine you're
on a slow connection and you can't afford to have other programs
lagging out something that's important.

[toc] | [prev] | [next] | [standalone]


#78191

FromNicholas Cannon <nicholascannon1@gmail.com>
Date2014-09-22 22:49 -0700
Message-ID<4f95597e-52de-4446-b184-f0e50f698fc5@googlegroups.com>
In reply to#78135
The git hub has not actually been updated yet I am working on somethine else then committing the update. How would I stop the threads though. I'am using the Thread from threading function. 

[toc] | [prev] | [next] | [standalone]


#78192

FromChris Angelico <rosuav@gmail.com>
Date2014-09-23 15:54 +1000
Message-ID<mailman.14241.1411451692.18130.python-list@python.org>
In reply to#78191
On Tue, Sep 23, 2014 at 3:49 PM, Nicholas Cannon
<nicholascannon1@gmail.com> wrote:
> The git hub has not actually been updated yet I am working on somethine else then committing the update. How would I stop the threads though. I'am using the Thread from threading function.
>

Ah, okay. (Side point: I recommend committing early and often, it
makes it much easier to go back and look at stuff later.) The easiest
way is to just set a global variable, and then have the thread
periodically check that - once it's set, it shuts itself down.

ChrisA

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web