Damian Brunold

File locking in Python

2010-01-22 10:45 Linux, Programmieren, Python

Mit diesem Code kann man File Locking in Python (unter Linux) machen:

   import fcntl

   lockfile = open('lock.lck', 'w')
   fcntl.flock(lockfile.fileno(), fcntl.LOCK_EX)
   try:
       # ...
   finally:
     fcntl.flock(lockfile.fileno(), fcntl.LOCK_UN)
     lockfile.close()