Seite 1 von 1

File locking

Verfasst: Dienstag 10. Mai 2005, 14:45
von HarryH
Hi,

Habe gerade das Modul 'msvcrt' in der Python-Doku gefunden.
Ist nur für Windows zu verwenden, bietet aber die Möglichkeit ein Datei zu sperren.
Es gibt dort folgende Funktion:
=> locking( fd, mode, nbytes)

Dabei gibt es fünf verschiedene Modi auszuwählen:
LK_LOCK
LK_RLCK

LK_NBLCK
LK_NBRLCK

LK_UNLCK
Doch was ist der Unterschied zwischen LK_LOCK und LK_RLCK, bzw. zwischen LK_NBLCK und LK_NBRLCK ?
Aus der Doku scheint das nicht hervorzugehen.
Vielleicht könnte mir von euch das einer erklären?
Danke!

Verfasst: Dienstag 10. Mai 2005, 14:53
von Leonidas
Hier ist es ein wenig detailierter erkärt. Soweit ich das verstehe, dürfen andere Prozesse die Datei dann noch lesen.

re:

Verfasst: Dienstag 10. Mai 2005, 14:56
von HarryH
Hi Leonidas,

Der von dir beigefügte Link funktioniert bei mir leider nicht. :roll:

Verfasst: Dienstag 10. Mai 2005, 15:12
von Leonidas
Sowas.. bei mir geht er, aber hier mal der Ausschnitt:
LK_UNLCK 0
Unlocks the specified region. The calling process releases a region of the file it had previously locked.

LK_LOCK 1
Locks the specified region. The calling process sleeps until the entire region is available if any part of it has been locked by a different process. The region is then locked for the calling process and no other process may read or write in any part of the locked region. (lock against read and write).

LK_NBLCK 2
Locks the specified region. If any part of the region is already locked by a different process, EACCES is returned instead of waiting for the region to become available for locking (nonblocking lockrequest).

LK_RLCK 3
Same as LK_LOCK except that the locked region may be read by other processes (read permitted lock).

LK_NBRLCK 4
Same as LK_NBLCK except that the locked region may be read by other processes (nonblocking, read permitted lock).