Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions mbed_lstools/lstools_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import lockfile
from os import listdir
from os.path import isfile, join
from lockfile import LockFailed
from lockfile import LockFailed, LockTimeout

class MbedLsToolsBase:
""" Base class for mbed-lstools, defines mbed-ls tools interface for mbed-enabled devices detection for various hosts
Expand Down Expand Up @@ -252,16 +252,21 @@ def read_mock_file(filename):
return {}

try:
with self.mbedls_get_global_lock():
lock = self.mbedls_get_global_lock()
if lock.acquire(timeout=0.5):
# This read is for backward compatibility
# When user already have on its system local mock-up it will work
# overwriting global one
if isfile(self.MOCK_FILE_NAME):
return read_mock_file(self.MOCK_FILE_NAME)
ret = read_mock_file(self.MOCK_FILE_NAME)
lock.release()
return ret

if isfile(self.MOCK_HOME_FILE_NAME):
return read_mock_file(self.MOCK_HOME_FILE_NAME)
except LockFailed as e:
ret = read_mock_file(self.MOCK_HOME_FILE_NAME)
lock.release()
return ret
except (LockFailed, LockTimeout) as e:
self.err(str(e))
return {}

Expand All @@ -284,9 +289,12 @@ def write_mock_file(filename, mock_ids):
return False

try:
with self.mbedls_get_global_lock():
return write_mock_file(self.MOCK_HOME_FILE_NAME, mock_ids)
except LockFailed as e:
lock = self.mbedls_get_global_lock()
if lock.acquire(timeout=0.5):
ret = write_mock_file(self.MOCK_HOME_FILE_NAME, mock_ids)
lock.release()
return ret
except (LockFailed, LockTimeout) as e:
self.err(str(e))
return False

Expand Down