Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 01-15-2008, 03:14 PM   #1
Senior Member
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Rep: Reputation: 51
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?
Old 10-11-2010, 03:33 AM   #2
Registered: Jun 2004
Location: FL, USA
Distribution: Slackware 9.1
Posts: 190

Rep: Reputation: 30
I believe it is commonly recommended to never update the GUI through a thread, always the main.
Old 10-11-2010, 11:28 AM   #3
Senior Member
Registered: Sep 2006
Location: Liverpool - England
Distribution: slackware64 13.37 and -current, Dragonfly BSD
Posts: 1,810

Rep: Reputation: 232Reputation: 232Reputation: 232
Have a look at wxAnyThread which is in the PyPI and looks useful. Note this quoted from the module :
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.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Thread-safe global variables in C JoeyAdams Programming 12 06-20-2012 08:52 PM
is Pam Thread Safe??? ptobra Programming 4 07-24-2007 09:19 PM
Thread safety jkoshi Linux - Software 3 05-03-2007 01:03 PM
What is thread safe....??? rajsun Programming 5 04-26-2005 11:33 PM
Thread Safety on PHP Gerardoj Linux - General 2 03-28-2004 06:22 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:16 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration