Protect proxy/filter models with write_lock

This commit is contained in:
miruka 2020-05-30 18:13:45 -04:00
parent 9862e39108
commit de894ab4bb
3 changed files with 57 additions and 50 deletions

View File

@ -33,11 +33,14 @@ class ModelFilter(ModelProxy):
value: "ModelItem",
_changed_fields: Optional[Dict[str, Any]] = None,
) -> None:
with self.write_lock:
if self.accept_source(source):
value = self.convert_item(value)
if self.accept_item(value):
self.__setitem__((source.sync_id, key), value, _changed_fields)
self.__setitem__(
(source.sync_id, key), value, _changed_fields,
)
self.filtered_out.pop((source.sync_id, key), None)
else:
self.filtered_out[source.sync_id, key] = value
@ -48,6 +51,7 @@ class ModelFilter(ModelProxy):
def source_item_deleted(self, source: Model, key) -> None:
with self.write_lock:
if self.accept_source(source):
try:
del self[source.sync_id, key]
@ -59,6 +63,7 @@ class ModelFilter(ModelProxy):
def source_cleared(self, source: Model) -> None:
with self.write_lock:
if self.accept_source(source):
for source_sync_id, key in self.copy():
if source_sync_id == source.sync_id:

View File

@ -188,6 +188,7 @@ class Model(MutableMapping):
and one `ModelItemDeleted` pyotherside event is fired per sequence.
"""
with self.write_lock:
try:
self._active_batch_remove_indice = []
yield None

View File

@ -17,6 +17,7 @@ class ModelProxy(Model):
self.take_items_ownership = False
Model.proxies[sync_id] = self
with self.write_lock:
for sync_id, model in Model.instances.items():
if sync_id != self.sync_id and self.accept_source(model):
for key, item in model.items():