Why not use this? from contextlib import nested with nested(lock, open(infile), open(outfile, 'w')) as (_, fin, fout): fout.write(fin.read()) Ok, the _ is ugly, but is it ugly enough so we need this extension to the with statement? -panzi