A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2005-May/053295.html below:

[Python-Dev] PEP 340 -- concept clarification

[Python-Dev] PEP 340 -- concept clarification [Python-Dev] PEP 340 -- concept clarificationNick Coghlan ncoghlan at gmail.com
Wed May 4 12:25:32 CEST 2005
James Y Knight wrote:
> On May 3, 2005, at 12:53 PM, Guido van Rossum wrote:
> 
>>def saving_stdout(f):
>>    save_stdout = sys.stdout
>>    try:
>>        sys.stdout = f
>>        yield
>>    finally:
>>        sys.stdout = save_stdout
> 
> 
> I hope you aren't going to be using that in any threaded program. 

sys.stdout is a global - threading issues are inherent in monkeying with it. At 
least this approach allows all code that redirects stdout to be easily serialised:

def redirect_stdout(f, the_lock=Lock()):
     locking(the_lock):
         save_stdout = sys.stdout
         try:
             sys.stdout = f
             yield
         finally:
             sys.stdout = save_stdout

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
---------------------------------------------------------------
             http://boredomandlaziness.skystorm.net
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4