Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #50848
| Newsgroups | comp.lang.python |
|---|---|
| Date | 2013-07-18 02:10 -0700 |
| References | (9 earlier) <mailman.4805.1374082807.3114.python-list@python.org> <78c6218b-2da8-41a0-9eb3-5432093b3f6b@googlegroups.com> <mailman.4818.1374109662.3114.python-list@python.org> <5dd8666d-abc1-41e7-9050-a9b95fbe1e16@googlegroups.com> <ks84kp$cr8$1@dont-email.me> |
| Message-ID | <8bd3de87-3f7d-48a7-ab1c-b55700c9178d@googlegroups.com> (permalink) |
| Subject | Re: tkinter redraw rates |
| From | fronagzen@gmail.com |
On Thursday, July 18, 2013 3:20:28 PM UTC+8, Christian Gollwitzer wrote:
> Am 18.07.13 06:38, schrieb fronagzen@gmail.com:
> > On Thursday, July 18, 2013 9:07:24 AM UTC+8, Dave Angel wrote:
> >> Nope - don't use that. Instead, post an event on the queue, and return
> >> to the mainloop() from whence we came.
> >> def test_thread(self):
> >> if self.loader_thread.isAlive():
> >> self.root_window.after(100, self.test_thread)
> >> return
> > I see, though it should be noted that your method doesn't actually
> > block the rest of the even handler code from running, had to fiddle
> > with it a bit to get that to work. May I ask what exactly is the
> > rationale behind implementing it like this, though?
> Exactly this is the goal of it. Event handlers are supposed to run in as
> short time as possible, and should never block. The reason is that you
> want the events to be processed in the order they come in, such that he
> user can still move the window, resize it, iconify/maximize etc.
> That said, the code still looks odd to me. I have used the Tk with
> multithreading in the past, but directly from Tcl, and not from Python.
> The basic idea is to have the background thread (which does the work)
> signal the main thread about its status, i.e. in the worker thread:
> for i in range(50):
> some_odd_computation()
> signal('progress', i)
> signal('finished')
> and in the main thread you bind() to the events fired from the worker
> thread. That way you don't run any periodic polling.
> I fear that Tkinter has a shortcoming which does not allow this pattern
> to be implemented. The tricky thing is to implement this signal()
> function, which must post an event to another thread. From the C level,
> there is Tcl_ThreadQueueEvent() which does this. It arranges for a C
> function to be run from the event loop of another thread. From Tcl,
> thread::send does this. To use it from Tkinter, it would be necessary to
> create a Tcl interpreter in the worker thread *without* loading Tk.
> Some day I should dive into the innards of Tkinter to see if this is
> possible. Then you could implement signal() simply by
> def signal(sig, data=''):
> tclinterp.eval('thread::send -async $mainthread {event generate .
> <<%s>> -data {%s}'%sig%data)
> and in the main thread bind() to the virtual events.
> Christian
Ah, I see. Thank you for your help!
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
tkinter redraw rates fronagzen@gmail.com - 2013-07-16 17:57 -0700
Re: tkinter redraw rates David Hutto <dwightdhutto@gmail.com> - 2013-07-16 21:32 -0400
Re: tkinter redraw rates David Hutto <dwightdhutto@gmail.com> - 2013-07-16 21:34 -0400
Re: tkinter redraw rates Dave Angel <davea@davea.name> - 2013-07-16 21:40 -0400
Re: tkinter redraw rates fronagzen@gmail.com - 2013-07-16 18:51 -0700
Re: tkinter redraw rates Dave Angel <davea@davea.name> - 2013-07-16 22:21 -0400
Re: tkinter redraw rates fronagzen@gmail.com - 2013-07-16 20:04 -0700
Re: tkinter redraw rates Dave Angel <davea@davea.name> - 2013-07-17 06:07 -0400
Re: tkinter redraw rates fronagzen@gmail.com - 2013-07-17 04:08 -0700
Re: tkinter redraw rates Michael Torrie <torriem@gmail.com> - 2013-07-17 16:53 -0600
Re: tkinter redraw rates fronagzen@gmail.com - 2013-07-17 04:10 -0700
Re: tkinter redraw rates Dave Angel <davea@davea.name> - 2013-07-17 07:42 -0400
Re: tkinter redraw rates fronagzen@gmail.com - 2013-07-17 06:18 -0700
Re: tkinter redraw rates Dave Angel <davea@davea.name> - 2013-07-17 13:38 -0400
Re: tkinter redraw rates fronagzen@gmail.com - 2013-07-17 17:44 -0700
Re: tkinter redraw rates Dave Angel <davea@davea.name> - 2013-07-17 21:07 -0400
Re: tkinter redraw rates fronagzen@gmail.com - 2013-07-17 21:38 -0700
Re: tkinter redraw rates Dave Angel <davea@davea.name> - 2013-07-18 00:52 -0400
Re: tkinter redraw rates Christian Gollwitzer <auriocus@gmx.de> - 2013-07-18 09:20 +0200
Re: tkinter redraw rates fronagzen@gmail.com - 2013-07-18 02:10 -0700
Re: tkinter redraw rates Peter Otten <__peter__@web.de> - 2013-07-17 20:10 +0200
csiph-web