write to the same file from multiple processes at the same time?
Do Re Mi chel La Si Do
enleverlesO.OmcO at OmclaveauO.com
Sat May 28 03:10:44 EDT 2005
Hi !
On windows, with PyWin32, to read this little sample-code :
import time
import win32file, win32con, pywintypes
def flock(file):
hfile = win32file._get_osfhandle(file.fileno())
win32file.LockFileEx(hfile, win32con.LOCKFILE_EXCLUSIVE_LOCK, 0, 0xffff,
pywintypes.OVERLAPPED())
def funlock(file):
hfile = win32file._get_osfhandle(file.fileno())
win32file.UnlockFileEx(hfile, 0, 0xffff, pywintypes.OVERLAPPED())
file = open("FLock.txt", "r+")
flock(file)
file.seek(123)
for i in range(500):
file.write("AAAAAAAAAA")
print i
time.sleep(0.001)
#funlock(file)
file.close()
Michel Claveau
More information about the Python-list
mailing list