Skip to content

Commit 216c3bd

Browse files
committed
tweak _do_upload running outside of class to prevent threads mix
1 parent 13b8ccb commit 216c3bd

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

mergin/client.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def __init__(
106106
self._user_info = None
107107
self._server_type = None
108108
self._server_version = None
109-
self._feature_flags = {}
109+
self._server_features = {}
110110
self.upload_chunks_cache = UploadChunksCache()
111111
self.client_version = "Python-client/" + __version__
112112
if plugin_version is not None: # this could be e.g. "Plugin/2020.1 QGIS/3.14"
@@ -396,14 +396,15 @@ def server_features(self):
396396
"""
397397
Returns feature flags of the server.
398398
"""
399-
if self._feature_flags:
400-
return self._feature_flags
399+
if self._server_features:
400+
return self._server_features
401401
config = self.server_config()
402-
return {
402+
self._server_features = {
403403
"v2_push_enabled": config.get("v2_push_enabled", False)
404-
and is_version_acceptable(self.server_version(), "2025.6.2"),
404+
and is_version_acceptable(self.server_version(), "2025.6.1"),
405405
"v2_pull_enabled": config.get("v2_pull_enabled", False),
406406
}
407+
return self._server_features
407408

408409
def workspaces_list(self):
409410
"""

mergin/client_push.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@
2323
from .merginproject import MerginProject
2424
from .editor import filter_changes
2525

26+
def _do_upload(item, job):
27+
"""runs in worker thread, have to be defined here to avoid worker threads repeating this function"""
28+
if job.is_cancelled:
29+
return
30+
31+
item.upload_blocking()
32+
job.transferred_size += item.size
33+
2634

2735
class UploadChunksCache:
2836
"""A cache for uploaded chunks to avoid re-uploading them, using checksum as key."""
@@ -101,14 +109,12 @@ def upload_blocking(self):
101109
checksum_str = checksum.hexdigest()
102110

103111
self.mp.log.debug(f"Uploading {self.file_path} part={self.chunk_index}")
104-
105112
if self.mc.server_features().get("v2_push_enabled"):
106113
# use v2 API for uploading chunks
107114
self.upload_chunk_v2_api(data, checksum_str)
108115
else:
109116
# use v1 API for uploading chunks
110117
self.upload_chunk(data, checksum_str)
111-
self.mc.upload_chunks_cache.add(checksum_str, self.chunk_id)
112118

113119
self.mp.log.debug(f"Upload chunk finished: {self.file_path}")
114120

@@ -138,17 +144,10 @@ def dump(self):
138144
print("- {} {} {}".format(item.file_path, item.chunk_index, item.size))
139145
print("--- END ---")
140146

141-
def __upload_item(self, item: UploadQueueItem):
142-
"""Upload a single item in the background"""
143-
if self.is_cancelled:
144-
return
145-
146-
item.upload_blocking()
147-
self.transferred_size += item.size
148147

149148
def submit_item_to_thread(self, item: UploadQueueItem):
150149
"""Upload a single item in the background"""
151-
feature = self.executor.submit(self.__upload_item, item)
150+
feature = self.executor.submit(_do_upload, item, self)
152151
self.futures.append(feature)
153152

154153
def add_items(self, items: List[UploadQueueItem], total_size: int):

0 commit comments

Comments
 (0)