[Tkinter-discuss] tkinter and multiprocessing
Mark Summerfield
list at qtrac.plus.com
Thu Aug 30 09:05:38 CEST 2012
Hi,
Silly me! I forgot to do the multiprocessing in a separate thread: now
it works:-)
On Wed, 29 Aug 2012 18:01:24 +0100
Mark Summerfield <list at qtrac.plus.com> wrote:
> Hi,
>
> I'm trying to create a Tkinter application that uses multiprocessing in
> a separate module to do some work.
>
> In the Tkinter part I have this method of my Window ttk.Frame subclass:
>
> def report(self, future):
> with StatusLock: # Serialize calls to Window.report()
> if future.exception() is None:
> result = future.result()
> print(result)
> # TODO why does this lock the application?
> self.statusText.set(result.name)
> self.master.update() # Make sure the GUI refreshes
>
> StatusLock is a multiprocessing.Lock.
> self.statusText is a tk.StringVar.
>
> This function is called by a multiprocessing Future:
>
> future = executor.submit(action, arg1, arg2)
> future.add_done_callback(report)
>
> When I run the program with the last two lines of report() commented out
> it correctly prints each result on the console. But with the last two
> lines uncommented it prints one result and then the whole application
> locks at the self.statusText.set() call.
>
> According to the multiprocessing docs the callback is executed in the
> thread of the function it is passed -- so in this case in the GUI thread
> which is what is wanted.
>
> Any suggestions/help welcome:-)
>
> Thanks!
--
Mark Summerfield, Qtrac Ltd, www.qtrac.eu
C++, Python, Qt, PyQt - training and consultancy
"Programming in Go" - ISBN 0321774639
http://www.qtrac.eu/gobook.html
More information about the Tkinter-discuss
mailing list