Skip to content

Commit 00006c7

Browse files
author
David Erb
committed
adds request lock
1 parent 9c3cc31 commit 00006c7

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

src/xchembku_lib/datafaces/aiohttp.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ async def activate_coro(self):
9393

9494
# Use a lock around all transaction-based requests.
9595
# TODO: Remove aiohttp transaction lock and instead use connection pool.
96-
self.__transaction_lock = asyncio.Lock()
96+
self.__request_lock = asyncio.Lock()
9797

9898
# Get the local implementation started.
9999
await self.__actual_dataface.start()
@@ -111,10 +111,9 @@ async def direct_shutdown(self):
111111
await self.__actual_dataface.disconnect()
112112

113113
except Exception as exception:
114-
raise RuntimeError(
114+
logger.warning(
115115
callsign(
116-
self,
117-
explain(exception, "disconnecting local xchembku_dataface"),
116+
self, explain(exception, "disconnecting actual xchembku_dataface")
118117
)
119118
)
120119

@@ -132,29 +131,30 @@ async def __do_actually(self, function, args, kwargs):
132131
# Get the function which the caller wants executed.
133132
function = getattr(self.__actual_dataface, function)
134133

135-
# Caller wants the function wrapped in a transaction?
136-
if "as_transaction" in kwargs:
137-
as_transaction = kwargs["as_transaction"]
138-
# Take the keyword out of the kwargs because the functions don't have it.
139-
kwargs.pop("as_transaction")
140-
else:
141-
as_transaction = False
134+
# Lock out all other requests from running at the same time.
135+
async with self.__request_lock:
136+
137+
# Caller wants the function wrapped in a transaction?
138+
if "as_transaction" in kwargs:
139+
as_transaction = kwargs["as_transaction"]
140+
# Take the keyword out of the kwargs because the functions don't have it.
141+
kwargs.pop("as_transaction")
142+
else:
143+
as_transaction = False
142144

143-
if as_transaction:
144-
# Make sure we have an actual connection.
145-
await self.__actual_dataface.establish_database_connection()
145+
if as_transaction:
146+
# Make sure we have an actual connection.
147+
await self.__actual_dataface.establish_database_connection()
146148

147-
# Lock out all other requests from running their own transaction.
148-
async with self.__transaction_lock:
149149
try:
150150
await self.__actual_dataface.begin()
151151
response = await function(*args, **kwargs)
152152
await self.__actual_dataface.commit()
153153
except Exception:
154154
await self.__actual_dataface.rollback()
155155
raise
156-
else:
157-
response = await function(*args, **kwargs)
156+
else:
157+
response = await function(*args, **kwargs)
158158

159159
return response
160160

0 commit comments

Comments
 (0)