Protect proxy/filter models with write_lock
This commit is contained in:
parent
9862e39108
commit
de894ab4bb
|
@ -33,11 +33,14 @@ class ModelFilter(ModelProxy):
|
||||||
value: "ModelItem",
|
value: "ModelItem",
|
||||||
_changed_fields: Optional[Dict[str, Any]] = None,
|
_changed_fields: Optional[Dict[str, Any]] = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
|
with self.write_lock:
|
||||||
if self.accept_source(source):
|
if self.accept_source(source):
|
||||||
value = self.convert_item(value)
|
value = self.convert_item(value)
|
||||||
|
|
||||||
if self.accept_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)
|
self.filtered_out.pop((source.sync_id, key), None)
|
||||||
else:
|
else:
|
||||||
self.filtered_out[source.sync_id, key] = value
|
self.filtered_out[source.sync_id, key] = value
|
||||||
|
@ -48,6 +51,7 @@ class ModelFilter(ModelProxy):
|
||||||
|
|
||||||
|
|
||||||
def source_item_deleted(self, source: Model, key) -> None:
|
def source_item_deleted(self, source: Model, key) -> None:
|
||||||
|
with self.write_lock:
|
||||||
if self.accept_source(source):
|
if self.accept_source(source):
|
||||||
try:
|
try:
|
||||||
del self[source.sync_id, key]
|
del self[source.sync_id, key]
|
||||||
|
@ -59,6 +63,7 @@ class ModelFilter(ModelProxy):
|
||||||
|
|
||||||
|
|
||||||
def source_cleared(self, source: Model) -> None:
|
def source_cleared(self, source: Model) -> None:
|
||||||
|
with self.write_lock:
|
||||||
if self.accept_source(source):
|
if self.accept_source(source):
|
||||||
for source_sync_id, key in self.copy():
|
for source_sync_id, key in self.copy():
|
||||||
if source_sync_id == source.sync_id:
|
if source_sync_id == source.sync_id:
|
||||||
|
|
|
@ -188,6 +188,7 @@ class Model(MutableMapping):
|
||||||
and one `ModelItemDeleted` pyotherside event is fired per sequence.
|
and one `ModelItemDeleted` pyotherside event is fired per sequence.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
with self.write_lock:
|
||||||
try:
|
try:
|
||||||
self._active_batch_remove_indice = []
|
self._active_batch_remove_indice = []
|
||||||
yield None
|
yield None
|
||||||
|
|
|
@ -17,6 +17,7 @@ class ModelProxy(Model):
|
||||||
self.take_items_ownership = False
|
self.take_items_ownership = False
|
||||||
Model.proxies[sync_id] = self
|
Model.proxies[sync_id] = self
|
||||||
|
|
||||||
|
with self.write_lock:
|
||||||
for sync_id, model in Model.instances.items():
|
for sync_id, model in Model.instances.items():
|
||||||
if sync_id != self.sync_id and self.accept_source(model):
|
if sync_id != self.sync_id and self.accept_source(model):
|
||||||
for key, item in model.items():
|
for key, item in model.items():
|
||||||
|
|
Loading…
Reference in New Issue
Block a user