File tree Expand file tree Collapse file tree 2 files changed +12
-6
lines changed
src/xchembku_lib/datafaces Expand file tree Collapse file tree 2 files changed +12
-6
lines changed Original file line number Diff line number Diff line change @@ -29,3 +29,4 @@ class Direct(
2929 # ----------------------------------------------------------------------------------------
3030 def __init__ (self , specification = None ):
3131 DirectBase .__init__ (self , specification )
32+ DirectCrystalWellDroplocations .__init__ (self , specification )
Original file line number Diff line number Diff line change 1+ import asyncio
12import copy
23import logging
3- from threading import RLock
44from typing import Dict , List , Optional
55
66from dls_normsql .constants import CommonFieldnames
1414
1515logger = logging .getLogger (__name__ )
1616
17- # Module-level lock to keep upsert atomic.
18- upsert_lock = RLock ()
19-
2017
2118class DirectCrystalWellDroplocations (DirectBase ):
2219 """ """
2320
21+ # ----------------------------------------------------------------------------------------
22+ def __init__ (self , specification = None ):
23+
24+ # Lock allows only one coroutine to acquire it at a time.
25+ self .__upsert_lock = asyncio .Lock ()
26+
2427 # ----------------------------------------------------------------------------------------
2528 async def upsert_crystal_well_droplocations_serialized (
2629 self ,
@@ -104,8 +107,10 @@ async def upsert_crystal_well_droplocations(
104107
105108 # Loop over all the models to be upserted.
106109 for model in models :
107- # TODO: Reconsider the lock granularity in direct_crystal_well_droplocations.py.
108- with upsert_lock :
110+ # Need to lock because of possible long time between query and eventual insert, user might double-click to send two droplocations quite quickly.
111+ # TODO: Reconsider direct_crystal_well_droplocations upsert logic to be tolerant of multiple processes possibly doing concurrent insert.
112+ # TODO: Add unit test for concurrent direct_crystal_well_droplocations upsert.
113+ async with self .__upsert_lock :
109114 model_dict = copy .deepcopy (model .dict ())
110115
111116 # Find any existing record for this model object.
You can’t perform that action at this time.
0 commit comments