Skip to content

Commit 12b0a03

Browse files
committed
(joe) ...
1 parent a7b6991 commit 12b0a03

File tree

4 files changed

+61
-54
lines changed

4 files changed

+61
-54
lines changed

locking/__init__.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@
22
xxx
33
"""
44

5-
class CouldNotLockException(Exception):
6-
pass
75

86
from .baselock import BaseLock
97
from .dynamolock import DynamoLock
108
from .filelock import FileLock
119
from .redislock import RedisLock
1210
from .socketlock import SocketLock
1311
from .utils import get_caller
12+
13+
__all__ = [
14+
DynamoLock,
15+
FileLock,
16+
RedisLock,
17+
SocketLock,
18+
]

locking/baselock.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22
import time
33
import random
44

5-
from . import CouldNotLockException
65
from .utils import get_caller
76

87
TIMEOUT_MAX = int(sys.maxsize / 10**9)
98

109

10+
class CouldNotLockException(Exception):
11+
pass
12+
13+
1114
class BaseLock(object):
1215

1316
def __init__(self, lockname=None, block=True):

locking/custom_exceptions.py

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class CouldNotLockException(Exception):
2+
pass

locking/tests/test_locks.py

+48-51
Original file line numberDiff line numberDiff line change
@@ -2,60 +2,57 @@
22
import time
33
from _thread import start_new_thread
44

5-
import lock_tests
5+
RUNNING_ON_CI = True
6+
try:
7+
import lock_tests
8+
except ImportError:
9+
from test import lock_tests
10+
RUNNING_ON_CI = False
611
from .. import DynamoLock, FileLock, RedisLock, SocketLock
712

8-
RUNNING_ON_CI = True
9-
# try:
10-
# RUNNING_ON_CI = True
11-
# except ImportError:
12-
# RUNNING_ON_CI = False
13-
# from test import lock_tests, support
14-
15-
16-
if True:
17-
class SocketLockTests(lock_tests.LockTests):
18-
locktype = staticmethod(SocketLock)
19-
20-
class FileLockTests(lock_tests.LockTests):
21-
locktype = staticmethod(FileLock)
22-
23-
if not RUNNING_ON_CI:
24-
class DynamoLockTests(lock_tests.LockTests):
25-
locktype = staticmethod(DynamoLock)
26-
27-
def tearDown(self):
28-
for ithread in threading.enumerate():
29-
if hasattr(ithread, 'exit_flag'):
30-
ithread.exit_flag.set()
31-
ithread.join()
32-
33-
def test_reacquire(self):
34-
"""Copied in because the wait_threads_exit """
35-
# Lock needs to be released before re-acquiring.
36-
lock = self.locktype()
37-
phase = []
38-
39-
def f():
40-
lock.acquire()
41-
phase.append(None)
42-
lock.acquire()
43-
phase.append(None)
44-
45-
with lock_tests.support.wait_threads_exit(timeout=5):
46-
start_new_thread(f, ())
47-
while len(phase) == 0:
48-
_wait()
13+
14+
class SocketLockTests(lock_tests.LockTests):
15+
locktype = staticmethod(SocketLock)
16+
17+
class FileLockTests(lock_tests.LockTests):
18+
locktype = staticmethod(FileLock)
19+
20+
if not RUNNING_ON_CI:
21+
class DynamoLockTests(lock_tests.LockTests):
22+
locktype = staticmethod(DynamoLock)
23+
24+
def tearDown(self):
25+
for ithread in threading.enumerate():
26+
if hasattr(ithread, 'exit_flag'):
27+
ithread.exit_flag.set()
28+
ithread.join()
29+
30+
def test_reacquire(self):
31+
"""Copied in because the wait_threads_exit """
32+
# Lock needs to be released before re-acquiring.
33+
lock = self.locktype()
34+
phase = []
35+
36+
def f():
37+
lock.acquire()
38+
phase.append(None)
39+
lock.acquire()
40+
phase.append(None)
41+
42+
with lock_tests.support.wait_threads_exit(timeout=5):
43+
start_new_thread(f, ())
44+
while len(phase) == 0:
4945
_wait()
50-
self.assertEqual(len(phase), 1)
51-
lock.release()
52-
while len(phase) == 1:
53-
_wait()
54-
self.assertEqual(len(phase), 2)
55-
lock.release()
56-
57-
def test_thread_leak(self):
58-
pass
46+
_wait()
47+
self.assertEqual(len(phase), 1)
48+
lock.release()
49+
while len(phase) == 1:
50+
_wait()
51+
self.assertEqual(len(phase), 2)
52+
lock.release()
53+
54+
def test_thread_leak(self):
55+
pass
5956

6057

6158
def _wait():

0 commit comments

Comments
 (0)