From 46fdbe786713125ac7c5d270d8276b47fca3da2a Mon Sep 17 00:00:00 2001 From: fijal Date: Mon, 27 Aug 2007 10:45:03 +0200 Subject: [PATCH] [svn r46010] Merge from branch - a lock for files, prevents segfaults of cpython --HG-- branch : trunk --- py/execnet/inputoutput.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/py/execnet/inputoutput.py b/py/execnet/inputoutput.py index 23facc6b0..2d431ec62 100644 --- a/py/execnet/inputoutput.py +++ b/py/execnet/inputoutput.py @@ -3,7 +3,7 @@ across process or computer barriers. """ -import socket, os, sys +import socket, os, sys, thread class SocketIO: server_stmt = """ @@ -76,6 +76,7 @@ sys.stdout = sys.stderr = StringIO.StringIO() msvcrt.setmode(outfile.fileno(), os.O_BINARY) self.outfile, self.infile = infile, outfile self.readable = self.writeable = True + self.lock = thread.allocate_lock() def read(self, numbytes): """Read exactly 'bytes' bytes from the pipe. """ @@ -99,6 +100,10 @@ sys.stdout = sys.stderr = StringIO.StringIO() self.infile.close() self.readable = None def close_write(self): - if self.writeable: - self.outfile.close() - self.writeable = None + self.lock.acquire() + try: + if self.writeable: + self.outfile.close() + self.writeable = None + finally: + self.lock.release()