Multithreaded wxPython app.

Hi!

I've been trying to use the example of the LongRunningTasks in the wiki (http://wiki.wxpython.org/index.cgi/LongRunningTasks) to execute an external application from the gui without having to wait for it to end.

However, if we run an external application which lasts for a while, e.g., running "wait 10" with a method like this:

def execute(command):
    child = popen2.Popen3(command,capturestderr=True)

    outdata = child.fromchild.read()
    errdata = child.childerr.read()

    err = child.wait()
    return (outdata,errdata,err)

and attempt to abort the thread, this only happens when the external application ends its 10 seconds execution because the execution is continuous contrary to what happens with the incremental cycle example used on the wiki.

Any sugestion to get through this?

Tks in advance.

···

-----Original Message-----
From: Harald Stürzebecher [mailto:harald.stuerzebecher@gmail.com]
Sent: Sun 7/17/2005 9:06 AM
To: wxPython-users@lists.wxwidgets.org; phark52@yahoo.com
Cc:
Subject: Re: [wxPython-users] Multithreaded wxPython app.
2005/7/17, aa bb <phark52@yahoo.com>:

How would I get a seperate thread in my app to
interact with the main wxpython GUI?

You could try the "Threads" sample from the wxPython demo.

(Demo -> Process and Events -> Threads)

I want to be able
to open a window (wx.Frame) from the thread. How can I
have this interact with my main app?

http://wiki.wxpython.org/index.cgi/Frequently_20Asked_20Questions#head-392708089012ac4ae7373a24fe889e529f3783ae

http://wiki.wxpython.org/index.cgi/LongRunningTasks

The demo and the wxPython wiki are always good places to start looking at.

Hope that helped,
Harald Stürzebecher

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

Hello,

I've been trying to use the example of the LongRunningTasks in the wiki

(http://wiki.wxpython.org/index.cgi/LongRunningTasks)

to execute an external application from the gui without having to wait

for

it to end.

However, if we run an external application which lasts for a while, e.g.,
running "wait 10" with a method like this:

def execute(command):
   child = popen2.Popen3(command,capturestderr=True)

   outdata = child.fromchild.read()
   errdata = child.childerr.read()

   err = child.wait()
   return (outdata,errdata,err)

and attempt to abort the thread, this only happens when the external application
ends its 10 seconds execution because the execution is continuous contrary
to what happens with the incremental cycle example used on the wiki.

Any sugestion to get through this?

I may suggest you to use a separate process instead of a separate thread.
In the same page (LongRunningTasks) there is a pointer to a "process" module,
that is very nice and I use it also in my big app. You also get rid of the
Python Global Interpreter lock that may slow down the thread to 40% wrt
a separate process.
Obviously, if you need some output (or you need to control also the GUI
from the separate thread) it may be more complicated.

HTH.

Andrea.