Вы можете найти pylocker очень полезным. Его можно использовать для блокировки файла или для механизмов блокировки в целом, и к нему можно получить доступ сразу из нескольких процессов Python.
Если вы просто хотите заблокировать файл, вот как это работает:
import uuid
from pylocker import Locker
# create a unique lock pass. This can be any string.
lpass = str(uuid.uuid1())
# create locker instance.
FL = Locker(filePath='myfile.txt', lockPass=lpass, mode='w')
# aquire the lock
with FL as r:
# get the result
acquired, code, fd = r
# check if aquired.
if fd is not None:
print fd
fd.write("I have succesfuly aquired the lock !")
# no need to release anything or to close the file descriptor,
# with statement takes care of that. let's print fd and verify that.
print fd