[svn r46010] Merge from branch - a lock for files, prevents segfaults of cpython
--HG-- branch : trunk
This commit is contained in:
parent
ee7dc229f9
commit
46fdbe7867
|
@ -3,7 +3,7 @@
|
||||||
across process or computer barriers.
|
across process or computer barriers.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import socket, os, sys
|
import socket, os, sys, thread
|
||||||
|
|
||||||
class SocketIO:
|
class SocketIO:
|
||||||
server_stmt = """
|
server_stmt = """
|
||||||
|
@ -76,6 +76,7 @@ sys.stdout = sys.stderr = StringIO.StringIO()
|
||||||
msvcrt.setmode(outfile.fileno(), os.O_BINARY)
|
msvcrt.setmode(outfile.fileno(), os.O_BINARY)
|
||||||
self.outfile, self.infile = infile, outfile
|
self.outfile, self.infile = infile, outfile
|
||||||
self.readable = self.writeable = True
|
self.readable = self.writeable = True
|
||||||
|
self.lock = thread.allocate_lock()
|
||||||
|
|
||||||
def read(self, numbytes):
|
def read(self, numbytes):
|
||||||
"""Read exactly 'bytes' bytes from the pipe. """
|
"""Read exactly 'bytes' bytes from the pipe. """
|
||||||
|
@ -99,6 +100,10 @@ sys.stdout = sys.stderr = StringIO.StringIO()
|
||||||
self.infile.close()
|
self.infile.close()
|
||||||
self.readable = None
|
self.readable = None
|
||||||
def close_write(self):
|
def close_write(self):
|
||||||
if self.writeable:
|
self.lock.acquire()
|
||||||
self.outfile.close()
|
try:
|
||||||
self.writeable = None
|
if self.writeable:
|
||||||
|
self.outfile.close()
|
||||||
|
self.writeable = None
|
||||||
|
finally:
|
||||||
|
self.lock.release()
|
||||||
|
|
Loading…
Reference in New Issue