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


Groups > comp.lang.python > #78137

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

References <6dffdfb3-82b3-4746-8f39-d6bfa727f439@googlegroups.com>
Date 2014-09-22 21:56 +1000
Subject Re: How to not enable a user to close the root tkinter window
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.14194.1411387007.18130.python-list@python.org> (permalink)

Show all headers | View raw


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.

Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

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

csiph-web