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

Discussion in 'Python' started by akineko, Mar 20, 2009.

  1. akineko

    akineko Guest

    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()
     
    akineko, Mar 20, 2009
    #1
    1. Advertising

  2. akineko

    Guest

    On Mar 20, 4:36 am, akineko <> 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
     
    , Mar 20, 2009
    #2
    1. Advertising

  3. akineko

    akineko Guest

    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-

    >
    > 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
     
    akineko, Mar 20, 2009
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chad
    Replies:
    4
    Views:
    8,425
  2. hshdude
    Replies:
    12
    Views:
    1,110
    Dimitri Maziuk
    Nov 4, 2004
  3. bronby
    Replies:
    1
    Views:
    672
    Andrew Thompson
    Jul 15, 2005
  4. Mike Driscoll
    Replies:
    1
    Views:
    635
    bmullan
    Jun 14, 2010
  5. David M. Gauntt
    Replies:
    1
    Views:
    140
    Thomas 'PointedEars' Lahn
    Aug 11, 2004
Loading...

Share This Page