Re: [wxPython-users] Can the wxPython event loop be run in a non-main thread?

19 views
Skip to first unread message

Robin Dunn

unread,
Nov 15, 2006, 4:49:10 PM11/15/06
to wxPytho...@lists.wxwidgets.org
Peter Hansen wrote:
> Robin Dunn wrote:
>> Dan Eloff wrote:
>>> I use Twisted, which has to run as the main thread, so I will have to
>>> run the wxPython event loop in a seperate thread. (There are ways to
>>> run them in the same thread, but none are recommended for a serious,
>>> high volume, network application.)
>>>
>>> Can the wx event loop run as a seperate, non-main thread?
>>
>> Yes. Whichever thread is active when the wx.App object is created is
>> what wxWidgets will consider its 'main' thread.
>
> I understood it to be whichever thread *first imported* the wx module,
> not which one created the App.
>
> Was that ever true and, if so, when did it change? I can't see any
> comments in CHANGES.html about it.

Yes, that was previously the case. The change happened in the 2.5.x
timeframe when the core wxWidgets initialization was refactored to
happen at app creation time instead of when module is first loaded.
It's mentioned in the 2.6 Migration Guide:

"""
The import-startup-bootstrap process employed by wxPython was changed
such that wxWidgets and the underlying gui toolkit are not initialized
until the wx.App object is created (but before wx.App.OnInit is called.)
This was required because of some changes that were made to the C++
wxApp class.

There are both benefits and potential problems with this change. The
benefits are that you can import wxPython without requiring access to a
GUI (for checking version numbers, etc.) and that in a multi-threaded
environment the thread that creates the app object will now be the GUI
thread instead of the one that imports wxPython. Some potential problems
are that the C++ side of the "stock-objects" (wx.BLUE_PEN,
wx.TheColourDatabase, etc.) are not initialized until the wx.App object
is created, so you should not use them until after you have created your
wx.App object. If you do then an exception will be raised telling you
that the C++ object has not been initialized yet.

Also, you will probably not be able to do any kind of GUI or bitmap
operation unless you first have created an app object, (even on Windows
where most anything was possible before.)
"""

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!


Reply all
Reply to author
Forward
0 new messages