multiprocessing and Tk GUI program (won't work under Linux)
bieffe62 at gmail.com
bieffe62 at gmail.com
Fri Mar 20 10:41:21 CET 2009
On Mar 20, 4:36 am, akineko <akin... at gmail.com> wrote:
> Hello everyone,
> I have started using multiprocessing module, which is now available
> with Python 2.6.
> It definitely opens up new possibilities.
> Now, I developed a small GUI package, which is to be used from other
> It uses multiprocessing and Pipes are used to pump image data/command
> to the GUI process.
> (I used multiprocessing because I got stack size problem if I used
> It works great under Solaris environment, which is my primary
> development environment.
> When I tried the program under Linux (CentOS5), the program didn't
> work (it hung).
> My other programs that use multiprocessing work flawlessly under both
> Solaris and Linux.
> To investigate this problem, I create a much simpler test program. The
> test program uses only basic necessary codes, nothing else. But my
> simple test program still exhibits the same problem.
> My test program display a GUI Button using three possible approaches:
> (1) multiprocessing (Solaris - okay, Linux - hung)
> (2) threading (Solaris - okay, Linux - okay)
> (3) none (main thread) (Solaris - okay, Linux - okay)
> Is this a bug in a multiprocessing package? Or, I overlooked
> Any comments on resolving this problem will be greatly appreciated.
> The attached is my test program (sorry for posting a long program).
> Thank you!
> Aki Niimura
> #!/usr/bin/env python
> import sys, os
> import time
> import threading
> import multiprocessing
> from Tkinter import *
> ### class Panel
> class Panel:
> def __init__(self, subp='multip'):
> if subp == 'multip':
> print 'multiprocessing module to handle'
> # GUI process
> self.process1 = multiprocessing.Process(target=self.draw)
> elif subp == 'thread':
> print 'threading module to handle'
> # GUI thread
> self.thread1 = threading.Thread(target=self.draw)
> # self.thread1.setDaemon(1)
> print 'main thread to handle'
> def draw(self):
> self.root = Tk()
> w = Button(self.root, text='Exit', command=self.root.quit)
> ### Main routine
> def main():
> subp = 'multip'
> if len(sys.argv) >= 2:
> if not sys.argv in ['multip', 'thread', 'none',]:
> print 'Invalid option: %s' % sys.argv
> print "Valid options are 'multip', 'thread', 'none'"
> subp = sys.argv
> panel = Panel(subp)
> if subp == 'none':
> while 1:
> if __name__ == '__main__':
It is just a guess, but did you try making 'draw' a function and not a
I read that parameters to the subprocess function shall be pickable;
in your test
program, 'draw' as 'self' as parameter, which is a Tkinter.Panel, and
I read somewhere
that Tkinter objects are not pickable ...
More information about the Python-list