How to put a lock

Bala blk at srasys.co.in
Mon Jul 19 05:56:23 EDT 2004


Hi,
    From My Application, iam creating Multiple thread..
    Each thread will acesss this function RedirectStdOut.

    sys.stdout is a global pointer..

    So i got an exception called "I/O Operation on Closed File"..

    How to solve this problem..Kindly give some solution..

    is it possible to put a lock for each thread..so that one thread accessing the RedirectStdOut, other thread can wait untill the lock get released.

    if so, i kindly request you to give some sample program...

    
    
    def RedirectStdOut():
        print "This is stdout"
        oldStd = sys.stdout
        sys.stdout = open("c:\\std.out", "w")
        print "This is Redirecting stdout to a file"
        sys.stdout.flush()
        sys.stdout.close()
        sys.stdout = oldStd    


Thanks in advance

Regards
Bala
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20040719/49415dbe/attachment.html>


More information about the Python-list mailing list