mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-10 09:07:58 +01:00
[utils] locked_file: Fix non-blocking non-exclusive lock
This commit is contained in:
parent
fcfa8853e4
commit
b63837bce0
1 changed files with 5 additions and 8 deletions
|
@ -2190,18 +2190,15 @@ def _unlock_file(f):
|
|||
import fcntl
|
||||
|
||||
def _lock_file(f, exclusive, block):
|
||||
flags = fcntl.LOCK_EX if exclusive else fcntl.LOCK_SH
|
||||
if not block:
|
||||
flags |= fcntl.LOCK_NB
|
||||
try:
|
||||
fcntl.flock(f,
|
||||
fcntl.LOCK_SH if not exclusive
|
||||
else fcntl.LOCK_EX if block
|
||||
else fcntl.LOCK_EX | fcntl.LOCK_NB)
|
||||
fcntl.flock(f, flags)
|
||||
except BlockingIOError:
|
||||
raise
|
||||
except OSError: # AOSP does not have flock()
|
||||
fcntl.lockf(f,
|
||||
fcntl.LOCK_SH if not exclusive
|
||||
else fcntl.LOCK_EX if block
|
||||
else fcntl.LOCK_EX | fcntl.LOCK_NB)
|
||||
fcntl.lockf(f, flags)
|
||||
|
||||
def _unlock_file(f):
|
||||
try:
|
||||
|
|
Loading…
Reference in a new issue