Re: [wxPython-users] Problems in using wxPython in a multithreaded context
Python User
mec2paris at gmail.com
Tue Oct 23 07:03:18 PDT 2007
I tested to use a single wxApp and a single MainLoop for my application and
it seems to work.
My C application use many threads and many interpreters and I cannot use
many processes.
Now, I generate my UIs with the global function wx.CallAfter in the thread
of the MainLoop (so in the first interpreter) and with wx.CallAfter I can
use data and methods from other interpreters. I may import new modules and
change values in the thread of the mainLoop.
Now my C Code becomes :
{
PyEval_InitThreads();
Py_Initialize(); //First interpreter
PyImport_ImportModule("myModule");//I create a wxApp + UIs + MainLoop
in a new thread
Py_NewInterpreter() //second interpreter
PyImport_ImportModule("anotherModule"); //I create and print my UI
with wx.CallAfter
....
}
I would like to know if objects which are created or loaded from an event in
the UI of the second interpreter are located in the second interpreter or in
the interpreter of the MainLoop.
Thanks.
On 10/22/07, Robin Dunn <robin at alldunn.com> wrote:
>
> [Please set your mail client to use word-wrap at a reasonable width.]
>
> mec2paris paris wrote:
> > For my C application, I use many interpreters (withh the fonction
> Py_NewInterpreter()). For my needs, I create many GUI with wxPython and I
> have problems. Here is My C Code:
> >
> > {
> > PyEval_InitThreads();
> > Py_Initialize();
> >
> >
> >
> > PyImport_ImportModule("myModule");//it creates a wxApp object and a
> GUI (mainloop)
> > ......
> >
> >
> > Py_NewInterpreter();
> > PyImport_ImportModule("anotherModule");//it should create a new
> wxApp and a new GUI (with Mainloop)
> >
> >
> >
> > .....
> > }
> >
> > Unfortunately this code does not work. In fact, My C application which
> use many interpreters is seen by wxPython as a single application, and as
> wxPython is thread safe, it is not possible to create a second App.
> >
> >
> >
> > I have to use many interpreters to separate variables and to avoid links
> between modules.
> >
> > What could I do to create many GUI in different interpreters (each GUI
> have to be in a separate environment)???
> >
>
> Why do they need to be separate? Why couldn't you have a single wx.App
> and MainLoop (perhaps running in the C++ code) and then let your Python
> snippets create their frames to be run in that App and thread? Since
> GUIs use event dispatching and spend most of their time waiting for an
> event, there usually isn't much of a need for different parts of the UI
> to be running in different threads.
>
> On the other hand if you really do need the separate GUIs to be in
> separate parallel environments, then one approach you may want to
> consider is to use separate processes.
>
>
> --
> Robin Dunn
> Software Craftsman
> http://wxPython.org Java give you jitters? Relax with wxPython!
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: wxPython-users-unsubscribe at lists.wxwidgets.org
> For additional commands, e-mail: wxPython-users-help at lists.wxwidgets.org
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.wxwidgets.org/pipermail/wxpython-users/attachments/200710=
23/d4694e00/attachment.htm
More information about the wxpython-users
mailing list