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
> programs.
> 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
> threading)
>
> 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
> something?
>
> 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)
>             self.process1.start()
>         elif subp == 'thread':
>             print 'threading module to handle'
>             # GUI thread
>             self.thread1 = threading.Thread(target=self.draw)
>             self.thread1.start()
> #           self.thread1.setDaemon(1)
>         else:
>             print 'main thread to handle'
>             pass
>
>     def draw(self):
>         self.root = Tk()
>         w = Button(self.root, text='Exit', command=self.root.quit)
>         w.pack()
>         self.root.mainloop()
>
> ###
> ###     Main routine
> ###
>
> def main():
>     subp = 'multip'
>     if len(sys.argv) >= 2:
>         if not sys.argv[1] in ['multip', 'thread', 'none',]:
>             print 'Invalid option: %s' % sys.argv[1]
>             print "Valid options are 'multip', 'thread', 'none'"
>             sys.exit(1)
>         else:
>             subp = sys.argv[1]
>     panel = Panel(subp)
>     if subp == 'none':
>         panel.draw()
>     while 1:
>         time.sleep(1)
>     pass
>
> if __name__ == '__main__':
>     main()

It is just a guess, but did you try making 'draw' a function and not a
method?
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 ...

Ciao
----
FB



More information about the Python-list mailing list