LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   python thread safety: printing from thread to redirected stdout - safe? (http://www.linuxquestions.org/questions/programming-9/python-thread-safety-printing-from-thread-to-redirected-stdout-safe-613792/)

BrianK 01-15-2008 03:14 PM

python thread safety: printing from thread to redirected stdout - safe?
 
This is actually a wxPython GUI question, but may still fall under the generic python umbrella.

If I redirect stdout (which, in my case, will update a wxPython text control), then run a print command from a thread. The thread updates the GUI via print. Is this safe or should I communicate via thread & main & let main handle it?

ToothlessRebel 10-11-2010 03:33 AM

I believe it is commonly recommended to never update the GUI through a thread, always the main.

bgeddy 10-11-2010 11:28 AM

Have a look at wxAnyThread which is in the PyPI and looks useful. Note this quoted from the module :
Quote:

In wxPython, methods that alter the state of the GUI are only safe to call from the thread running the main event loop. Other threads must typically post events to the GUI thread instead of invoking methods directly.
I've not used the module myself, or indeed wxpython very much so can't comment on the quality.


All times are GMT -5. The time now is 04:00 AM.