Skip to content

Commit ccb68c9

Browse files
author
James William Pye
committed
Revert to the older style.
Wrong about 8.2. =\
1 parent 801f9bb commit ccb68c9

1 file changed

Lines changed: 20 additions & 28 deletions

File tree

postgresql/alock.py

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,15 @@ def mode(self):
3838
The mode of the lock class.
3939
"""
4040

41-
@abstractmethod
42-
def _try(self, id_pairs, ids):
43-
"""
44-
Try and acquire.
45-
"""
46-
47-
@abstractmethod
48-
def _acquire(self, id_pairs, ids):
49-
"""
50-
Acquire and wait if necessary.
41+
@abstractproperty
42+
def __select_statements__(self):
5143
"""
44+
Implemented by subclasses to return the statements to try, acquire, and
45+
release the advisory lock.
5246
53-
@abstractmethod
54-
def _release(self, id_pairs, ids):
55-
"""
56-
Release the locks.
47+
Returns a triple of callables where each callable takes two arguments,
48+
the lock-id pairs, and then the int8 lock-ids.
49+
``(try, acquire, release)``.
5750
"""
5851

5952
@staticmethod
@@ -141,25 +134,24 @@ def __init__(self, database, *identifiers):
141134
self.connection = self.database = database
142135
self.identifiers = identifiers
143136
self._id_pairs, self._ids = self._split_lock_identifiers(identifiers)
137+
self._try, self._acquire, self._release = self.__select_statements__()
144138

145139
class ShareLock(ALock):
146140
mode = 'share'
147-
def _try(self, *args):
148-
return self.database.sys.try_advisory_shared(*args)
149141

150-
def _acquire(self, *args):
151-
return self.database.sys.acquire_advisory_shared(*args)
152-
153-
def _release(self, *args):
154-
return self.database.sys.release_advisory_shared(*args)
142+
def __select_statements__(self):
143+
return (
144+
self.database.sys.try_advisory_shared,
145+
self.database.sys.acquire_advisory_shared,
146+
self.database.sys.release_advisory_shared,
147+
)
155148

156149
class ExclusiveLock(ALock):
157150
mode = 'exclusive'
158-
def _try(self, *args):
159-
return self.database.sys.try_advisory_exclusive(*args)
160-
161-
def _acquire(self, *args):
162-
return self.database.sys.acquire_advisory_exclusive(*args)
163151

164-
def _release(self, *args):
165-
return self.database.sys.release_advisory_exclusive(*args)
152+
def __select_statements__(self):
153+
return (
154+
self.database.sys.try_advisory_exclusive,
155+
self.database.sys.acquire_advisory_exclusive,
156+
self.database.sys.release_advisory_exclusive,
157+
)

0 commit comments

Comments
 (0)