multiprocessing and Tk GUI program (won't work under Linux)


A

akineko

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()
 
Ad

Advertisements

B

bieffe62

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
 
Ad

Advertisements

A

akineko

Hello FB,

Thank you for responding to my posting.
I have tried your suggestion, making a function rather than a method
in a class.
The result is still the same.
According to the documentation, objects to be sent through
'Connection' must be pickable.
But I couldn't find anything that explain the situation I'm having.
I will report this to Python bug tracker.
That way, the developer of multiprocessing module can try the test
case by himself.

Thanks,
Aki-
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top