Use ContainerRegistry.lockFile in Cura package management

Prevent concurrent I/O issues.
This commit is contained in:
Lipu Fei 2018-05-01 10:31:54 +02:00
parent cff4dc8a0c
commit 1fb2edace5

View file

@ -48,6 +48,9 @@ class CuraPackageManager(QObject):
Logger.log("i", "Package management file %s doesn't exist, do nothing", self._package_management_file_path)
return
# Need to use the file lock here to prevent concurrent I/O from other processes/threads
container_registry = self._application.getContainerRegistry()
with container_registry.lockFile():
with open(self._package_management_file_path, "r", encoding = "utf-8") as f:
management_dict = json.load(f, encoding = "utf-8")
@ -58,6 +61,9 @@ class CuraPackageManager(QObject):
Logger.log("i", "Package management file %s is loaded", self._package_management_file_path)
def _saveManagementData(self) -> None:
# Need to use the file lock here to prevent concurrent I/O from other processes/threads
container_registry = self._application.getContainerRegistry()
with container_registry.lockFile():
with open(self._package_management_file_path, "w", encoding = "utf-8") as f:
data_dict = {"installed": self._installed_package_dict,
"to_remove": list(self._to_remove_package_set),