Hi again,
I am not running the interpreter interactively but through a script.
In the script I run the extension (which is a long running task) in a
seperate thread using wx.lib.delayedresult. The sample code below
produces the behavior i describe. The first block of code is just to
set up the extension and not related to the problem. I run it on OSX.
The extension is C++ and the interface is generated using SWIG. It is
compiled using the C++ compiler through setuptools. Thanks again.
Kasper
···
########################################################
import Options
optionParser = Options.Options()
optionParser.options.project = '/Users/kasper/Desktop/guitest'
optionParser.postProcess()
from SAP.Sampling import Barcoder as plugin
extension = plugin.Sampler(optionParser.options)
########################################################
import wx
class MyFrame(wx.Frame):
def __init__(self, *args, **kwds):
kwds["style"] = wx.DEFAULT_FRAME_STYLE
wx.Frame.__init__(self, *args, **kwds)
class MyApp(wx.App):
def OnInit(self):
wx.InitAllImageHandlers()
frame_1 = MyFrame(None, -1, "")
frame_1.CenterOnScreen()
self.SetTopWindow(frame_1)
frame_1.Show()
return 1
def start_gui():
# If I call run method from the extension here it runs fine:
extension.run('/Users/kasper/Desktop/guitest/alignmentcache/test_50262771_sediment_one.nex')
app = MyApp(0)
# But if i call it here (or anywhere else after this point) the
whole thing hangs,
# I get "Python (Not Resonding)" in the Activity Monitor, and the
Python.app icon
# keeps jumping in the dock likek it is trying to start up without
succeeding.
extension.run('/Users/kasper/Desktop/guitest/alignmentcache/test_50262771_sediment_one.nex')
app.MainLoop()
if __name__ == "__main__":
start_gui()
Nathaniel Echols wrote:
I have written a nice GUI (very easy in wxPython). The GUI is meant to
run a task implemented as a C++ extension using SWIG. My extension
works fine when called before I invoke wxPython by subclassing wx.App,
but if I call it after, as I would obviously like to, it hangs (the
interpreter becomes unresponsive). Is there some reason why I can't
call a C++ extension form within wxPython? - And if so what can I do?It's not clear to me what phenomenon you're describing; are you
running the interpreter interactively, and is this happening after you
run App.MainLoop()? If it's simply a matter of the interpreter not
dying when you hit ctrl-C, that could be the fault of a bare 'except'
clause. I call various custom C++ extensions (using Boost.Python)
from wxPython all the time without a problem, but I often (though not
always) have to use threads to "detach" these from the main GUI
process, and I make sure to let KeyboardInterrupt exceptions through.
(wxPython itself is a C++ extension that uses SWIG [I think], so
there's no technical reason why what you want to do isn't possible.)Can you send some sample code?
-Nat
wxPython is a wrapper of the C++ wx GUI package. Robin "wraps" it
through the SWIG process. Anyway, it sounds like the OP is running a
process that is blocking wx's mainloop. Check out the wiki here:
http://wiki.wxpython.org/LongRunningTasks
-------------------
Mike Driscoll
--
Department of Integrative Biology
University of California, Berkeley
Office phone: (510) 643-6299