[appimage] database lock implemented

This commit is contained in:
Vinicius Moreira
2019-10-14 15:51:37 -03:00
parent ae7c914d13
commit d7c17c4aca
3 changed files with 55 additions and 19 deletions

18
bauh/gems/appimage/db.py Normal file
View File

@@ -0,0 +1,18 @@
import os
import time
def acquire_lock(db_path: str):
lock_path = db_path + '.lock'
while True:
if not os.path.exists(lock_path):
open(lock_path, 'a').close()
break
else:
time.sleep(0.0005)
def release_lock(db_path: str):
lock_path = db_path + '.lock'
if os.path.exists(lock_path):
os.remove(lock_path)