mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2025-06-18 06:06:14 +00:00
use the new get machine id code to fix a race condition bug
This commit is contained in:
parent
50d3129010
commit
5e580e6e2c
3 changed files with 77 additions and 20 deletions
40
resources/lib/Lock.py
Normal file
40
resources/lib/Lock.py
Normal file
|
@ -0,0 +1,40 @@
|
|||
import os
|
||||
import time
|
||||
import errno
|
||||
import xbmc
|
||||
|
||||
class Lock:
|
||||
|
||||
def __init__(self, filename):
|
||||
self.filename = filename
|
||||
self.delay = 0.5
|
||||
self.timeout = 10
|
||||
self.is_locked = False
|
||||
self.fd = None
|
||||
|
||||
def acquire(self):
|
||||
start_time = time.time()
|
||||
while True:
|
||||
try:
|
||||
self.fd = os.open(self.filename, os.O_CREAT|os.O_RDWR|os.O_EXCL)
|
||||
break;
|
||||
except OSError as e:
|
||||
if (time.time() - start_time) >= self.timeout:
|
||||
xbmc.log("File_Lock_On " + self.filename + " timed out")
|
||||
return False
|
||||
#xbmc.log("File_Lock_On " + self.filename + " error " + str(e))
|
||||
time.sleep(self.delay)
|
||||
self.is_locked = True
|
||||
xbmc.log("File_Lock_On " + self.filename + " obtained")
|
||||
return True
|
||||
|
||||
def release(self):
|
||||
if self.is_locked:
|
||||
os.close(self.fd)
|
||||
os.unlink(self.filename)
|
||||
self.is_locked = False
|
||||
xbmc.log("File_Lock_On " + self.filename + " released")
|
||||
|
||||
def __del__(self):
|
||||
self.release()
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue