zstdlib 0.10.10__tar.gz → 0.10.11__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {zstdlib-0.10.10 → zstdlib-0.10.11}/PKG-INFO +1 -1
- {zstdlib-0.10.10 → zstdlib-0.10.11}/tests/test_ip_lock.py +7 -15
- {zstdlib-0.10.10 → zstdlib-0.10.11}/tests/test_keyed_instance.py +6 -6
- {zstdlib-0.10.10 → zstdlib-0.10.11}/zstdlib/__init__.py +3 -8
- {zstdlib-0.10.10 → zstdlib-0.10.11}/zstdlib/ansi.py +2 -0
- {zstdlib-0.10.10 → zstdlib-0.10.11}/zstdlib/frozen.py +2 -0
- {zstdlib-0.10.10 → zstdlib-0.10.11}/zstdlib/ip_lock.py +19 -11
- {zstdlib-0.10.10 → zstdlib-0.10.11}/zstdlib/keyed_instance.py +4 -4
- {zstdlib-0.10.10 → zstdlib-0.10.11}/zstdlib/log/cute.py +2 -0
- {zstdlib-0.10.10 → zstdlib-0.10.11}/zstdlib/log/trace.py +2 -0
- {zstdlib-0.10.10 → zstdlib-0.10.11}/zstdlib/not_set.py +2 -0
- {zstdlib-0.10.10 → zstdlib-0.10.11}/zstdlib/signal_cm.py +4 -1
- {zstdlib-0.10.10 → zstdlib-0.10.11}/zstdlib/singleton.py +2 -0
- {zstdlib-0.10.10 → zstdlib-0.10.11}/zstdlib.egg-info/PKG-INFO +1 -1
- {zstdlib-0.10.10 → zstdlib-0.10.11}/LICENSE +0 -0
- {zstdlib-0.10.10 → zstdlib-0.10.11}/README.md +0 -0
- {zstdlib-0.10.10 → zstdlib-0.10.11}/pyproject.toml +0 -0
- {zstdlib-0.10.10 → zstdlib-0.10.11}/setup.cfg +0 -0
- {zstdlib-0.10.10 → zstdlib-0.10.11}/tests/__init__.py +0 -0
- {zstdlib-0.10.10 → zstdlib-0.10.11}/tests/log/__init__.py +0 -0
- {zstdlib-0.10.10 → zstdlib-0.10.11}/tests/log/base.py +0 -0
- {zstdlib-0.10.10 → zstdlib-0.10.11}/tests/log/test_cute.py +0 -0
- {zstdlib-0.10.10 → zstdlib-0.10.11}/tests/log/test_trace.py +0 -0
- {zstdlib-0.10.10 → zstdlib-0.10.11}/tests/test_ansi.py +0 -0
- {zstdlib-0.10.10 → zstdlib-0.10.11}/tests/test_enum.py +0 -0
- {zstdlib-0.10.10 → zstdlib-0.10.11}/tests/test_exc_capture.py +0 -0
- {zstdlib-0.10.10 → zstdlib-0.10.11}/tests/test_frozen.py +0 -0
- {zstdlib-0.10.10 → zstdlib-0.10.11}/tests/test_hybridmethod.py +0 -0
- {zstdlib-0.10.10 → zstdlib-0.10.11}/tests/test_io.py +0 -0
- {zstdlib-0.10.10 → zstdlib-0.10.11}/tests/test_lazy.py +0 -0
- {zstdlib-0.10.10 → zstdlib-0.10.11}/tests/test_not_set.py +0 -0
- {zstdlib-0.10.10 → zstdlib-0.10.11}/tests/test_prompt.py +0 -0
- {zstdlib-0.10.10 → zstdlib-0.10.11}/tests/test_singleton.py +0 -0
- {zstdlib-0.10.10 → zstdlib-0.10.11}/tests/test_util.py +0 -0
- {zstdlib-0.10.10 → zstdlib-0.10.11}/zstdlib/enum.py +0 -0
- {zstdlib-0.10.10 → zstdlib-0.10.11}/zstdlib/exc_capture.py +0 -0
- {zstdlib-0.10.10 → zstdlib-0.10.11}/zstdlib/hybridmethod.py +0 -0
- {zstdlib-0.10.10 → zstdlib-0.10.11}/zstdlib/io.py +0 -0
- {zstdlib-0.10.10 → zstdlib-0.10.11}/zstdlib/lazy.py +0 -0
- {zstdlib-0.10.10 → zstdlib-0.10.11}/zstdlib/log/__init__.py +0 -0
- {zstdlib-0.10.10 → zstdlib-0.10.11}/zstdlib/macos.py +0 -0
- {zstdlib-0.10.10 → zstdlib-0.10.11}/zstdlib/prompt.py +0 -0
- {zstdlib-0.10.10 → zstdlib-0.10.11}/zstdlib/py.typed +0 -0
- {zstdlib-0.10.10 → zstdlib-0.10.11}/zstdlib/util.py +0 -0
- {zstdlib-0.10.10 → zstdlib-0.10.11}/zstdlib.egg-info/SOURCES.txt +0 -0
- {zstdlib-0.10.10 → zstdlib-0.10.11}/zstdlib.egg-info/dependency_links.txt +0 -0
- {zstdlib-0.10.10 → zstdlib-0.10.11}/zstdlib.egg-info/requires.txt +0 -0
- {zstdlib-0.10.10 → zstdlib-0.10.11}/zstdlib.egg-info/top_level.txt +0 -0
|
@@ -9,16 +9,8 @@ import unittest
|
|
|
9
9
|
import time
|
|
10
10
|
import os
|
|
11
11
|
|
|
12
|
-
from zstdlib import
|
|
13
|
-
|
|
14
|
-
AbstractIPLock,
|
|
15
|
-
IPLock,
|
|
16
|
-
RIPLock,
|
|
17
|
-
LockHung,
|
|
18
|
-
LockPathInUse,
|
|
19
|
-
NotAcquired,
|
|
20
|
-
normpath,
|
|
21
|
-
)
|
|
12
|
+
from zstdlib.ip_lock import LockPathInUseError, NotAcquiredError, AbstractIPLock, LockHungError
|
|
13
|
+
from zstdlib import GlobalIPLock as GIPL, RIPLock, IPLock, normpath
|
|
22
14
|
|
|
23
15
|
DELAY = 0.25 # Lower is faster but less accurate
|
|
24
16
|
|
|
@@ -206,7 +198,7 @@ class TestGlobalProcessLock(unittest.TestCase):
|
|
|
206
198
|
lock.release()
|
|
207
199
|
self.assertFalse(lock.acquired)
|
|
208
200
|
# Release 3/2
|
|
209
|
-
with self.assertRaises(
|
|
201
|
+
with self.assertRaises(NotAcquiredError):
|
|
210
202
|
lock.release()
|
|
211
203
|
self.assertFalse(lock.acquired)
|
|
212
204
|
# CM exit, lock file removed by NTF
|
|
@@ -285,7 +277,7 @@ class TestIPLocks(unittest.TestCase):
|
|
|
285
277
|
# pylint: enable=protected-access
|
|
286
278
|
# Test releasing when we don't have
|
|
287
279
|
self.assertFalse(lock.acquired)
|
|
288
|
-
with self.assertRaises(
|
|
280
|
+
with self.assertRaises(NotAcquiredError):
|
|
289
281
|
lock.release()
|
|
290
282
|
# pylint: disable=protected-access
|
|
291
283
|
lock._rc += 1
|
|
@@ -334,15 +326,15 @@ class TestIPLocks(unittest.TestCase):
|
|
|
334
326
|
self.assertFalse(rlock.acquired)
|
|
335
327
|
del rlock
|
|
336
328
|
|
|
337
|
-
with mk_lock(IPLock) as lock, self.assertRaises(
|
|
329
|
+
with mk_lock(IPLock) as lock, self.assertRaises(LockPathInUseError):
|
|
338
330
|
_ = RIPLock(lock.path)
|
|
339
331
|
del lock
|
|
340
|
-
with mk_lock(RIPLock) as rlock, self.assertRaises(
|
|
332
|
+
with mk_lock(RIPLock) as rlock, self.assertRaises(LockPathInUseError):
|
|
341
333
|
_ = IPLock(rlock.path)
|
|
342
334
|
del rlock
|
|
343
335
|
|
|
344
336
|
def test_lock_hung(self) -> None:
|
|
345
|
-
with mk_lock(IPLock) as lock, enter(lock), self.assertRaises(
|
|
337
|
+
with mk_lock(IPLock) as lock, enter(lock), self.assertRaises(LockHungError):
|
|
346
338
|
_ = lock.acquire()
|
|
347
339
|
|
|
348
340
|
|
|
@@ -12,8 +12,8 @@ import time
|
|
|
12
12
|
import sys
|
|
13
13
|
import os
|
|
14
14
|
|
|
15
|
-
from zstdlib.keyed_instance import KeyedInstanceProcessError
|
|
16
|
-
from zstdlib import
|
|
15
|
+
from zstdlib.keyed_instance import CircularConstructionError, KeyedInstanceProcessError
|
|
16
|
+
from zstdlib import KeyedInstance
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
class Nop:
|
|
@@ -129,14 +129,14 @@ class TestKeyedInstance(unittest.TestCase):
|
|
|
129
129
|
def __init__(self, b: bool) -> None:
|
|
130
130
|
self.same = type(self)(b) # Father is self, circle
|
|
131
131
|
|
|
132
|
-
with self.assertRaises(
|
|
132
|
+
with self.assertRaises(CircularConstructionError):
|
|
133
133
|
_ = Crazy(True)
|
|
134
134
|
|
|
135
135
|
class Crazy2(KeyedInstance):
|
|
136
136
|
def __init__(self, b: bool) -> None:
|
|
137
137
|
self.inverse = type(self)(not b) # Grandfather is self
|
|
138
138
|
|
|
139
|
-
with self.assertRaises(
|
|
139
|
+
with self.assertRaises(CircularConstructionError):
|
|
140
140
|
_ = Crazy2(True)
|
|
141
141
|
|
|
142
142
|
def test_multiproc(self) -> None:
|
|
@@ -249,8 +249,8 @@ class TestKeyedInstance(unittest.TestCase):
|
|
|
249
249
|
"5 | Thread-1 | C1(0), next=[0, 0] - err: C2(0)", # release C2(0)
|
|
250
250
|
]
|
|
251
251
|
self.assertEqual(Action.strs(actions), expected)
|
|
252
|
-
self.assertIsInstance(fail1,
|
|
253
|
-
self.assertIsInstance(fail2,
|
|
252
|
+
self.assertIsInstance(fail1, CircularConstructionError)
|
|
253
|
+
self.assertIsInstance(fail2, CircularConstructionError)
|
|
254
254
|
self.assertIsNot(fail1, fail2)
|
|
255
255
|
|
|
256
256
|
# Test simultaneous construction
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
__version__ = "0.10.
|
|
1
|
+
__version__ = "0.10.11"
|
|
2
2
|
|
|
3
|
-
from .ip_lock import AbstractIPLock, GlobalIPLock, IPLock, LockHung, LockPathInUse, NotAcquired, RIPLock
|
|
4
|
-
from .keyed_instance import CircularConstruction, KeyedInstance
|
|
5
3
|
from .prompt import prompt_until, prompt_for, yn_prompt
|
|
4
|
+
from .ip_lock import GlobalIPLock, IPLock, RIPLock
|
|
6
5
|
from .exc_capture import ExcCapture, ExcDelay
|
|
6
|
+
from .keyed_instance import KeyedInstance
|
|
7
7
|
from .hybridmethod import hybridmethod
|
|
8
8
|
from .not_set import NotSetType, NotSet
|
|
9
9
|
from .frozen import Freezable, frozen
|
|
@@ -14,8 +14,6 @@ from .util import normpath
|
|
|
14
14
|
from . import macos, lazy, log, io
|
|
15
15
|
|
|
16
16
|
__all__ = (
|
|
17
|
-
"AbstractIPLock",
|
|
18
|
-
"CircularConstruction",
|
|
19
17
|
"Enum",
|
|
20
18
|
"ExcCapture",
|
|
21
19
|
"ExcDelay",
|
|
@@ -23,9 +21,6 @@ __all__ = (
|
|
|
23
21
|
"GlobalIPLock",
|
|
24
22
|
"IPLock",
|
|
25
23
|
"KeyedInstance",
|
|
26
|
-
"LockHung",
|
|
27
|
-
"LockPathInUse",
|
|
28
|
-
"NotAcquired",
|
|
29
24
|
"NotSet",
|
|
30
25
|
"NotSetType",
|
|
31
26
|
"RIPLock",
|
|
@@ -10,14 +10,22 @@ from fasteners import InterProcessLock
|
|
|
10
10
|
from .keyed_instance import KeyedInstance
|
|
11
11
|
from .util import normpath
|
|
12
12
|
|
|
13
|
-
__all__ = (
|
|
13
|
+
__all__ = (
|
|
14
|
+
"AbstractIPLock",
|
|
15
|
+
"GlobalIPLock",
|
|
16
|
+
"IPLock",
|
|
17
|
+
"LockHungError",
|
|
18
|
+
"LockPathInUseError",
|
|
19
|
+
"NotAcquiredError",
|
|
20
|
+
"RIPLock",
|
|
21
|
+
)
|
|
14
22
|
|
|
15
23
|
|
|
16
|
-
class
|
|
24
|
+
class NotAcquiredError(RuntimeError):
|
|
17
25
|
"""Raised by AbstractIPLock.release if a lock is not acquired"""
|
|
18
26
|
|
|
19
27
|
|
|
20
|
-
class
|
|
28
|
+
class LockHungError(RuntimeError):
|
|
21
29
|
"""Raised when a non-reentrant lock attempts to reenter with blocking=True and no timeout"""
|
|
22
30
|
|
|
23
31
|
|
|
@@ -42,7 +50,7 @@ class AbstractIPLock(ABC):
|
|
|
42
50
|
|
|
43
51
|
@abstractmethod
|
|
44
52
|
def release(self) -> None:
|
|
45
|
-
"""Release the lock, raises
|
|
53
|
+
"""Release the lock, raises NotAcquiredError if not self.acquired"""
|
|
46
54
|
|
|
47
55
|
# Concrete methods
|
|
48
56
|
|
|
@@ -160,7 +168,7 @@ class GlobalIPLock(KeyedInstance, AbstractIPLock):
|
|
|
160
168
|
def release(self) -> None:
|
|
161
169
|
"""Release the lock"""
|
|
162
170
|
if not self.acquired:
|
|
163
|
-
raise
|
|
171
|
+
raise NotAcquiredError(f"{self.__class__.__name__}: {self.path}")
|
|
164
172
|
with self._t_lock:
|
|
165
173
|
assert bool(self._rc) == self._ip_lock.acquired
|
|
166
174
|
if self._rc <= 1:
|
|
@@ -169,7 +177,7 @@ class GlobalIPLock(KeyedInstance, AbstractIPLock):
|
|
|
169
177
|
assert bool(self._rc) == self._ip_lock.acquired
|
|
170
178
|
|
|
171
179
|
|
|
172
|
-
class
|
|
180
|
+
class LockPathInUseError(LookupError):
|
|
173
181
|
"""
|
|
174
182
|
Raised when a user attempts to create an IPLock lock for a given
|
|
175
183
|
GlobalIPLock that already exists with a different reentrancy setting
|
|
@@ -195,7 +203,7 @@ class _IPLock(AbstractIPLock):
|
|
|
195
203
|
def __init__(self, gipl: GlobalIPLock | Path | str, *args: Any, **kwargs: Any) -> None:
|
|
196
204
|
"""
|
|
197
205
|
Construct an inter process lock syncronized by gipl (or GlobalIPLock.new(gipl) if str | Path)
|
|
198
|
-
If a lock of a different reentrancy setting already exists for this gipl, raise
|
|
206
|
+
If a lock of a different reentrancy setting already exists for this gipl, raise LockPathInUseError
|
|
199
207
|
"""
|
|
200
208
|
super().__init__(*args, **kwargs) # For MRO superclasses
|
|
201
209
|
if isinstance(gipl, Path | str):
|
|
@@ -209,7 +217,7 @@ class _IPLock(AbstractIPLock):
|
|
|
209
217
|
got = (self._cls_reentrant, Lock())
|
|
210
218
|
self._data[gipl.path] = got
|
|
211
219
|
if got[0] != self._cls_reentrant:
|
|
212
|
-
raise
|
|
220
|
+
raise LockPathInUseError(f"reentrant={self._cls_reentrant} but existing lock is the opposite")
|
|
213
221
|
self._instance_reentrant: Final[bool] = got[0]
|
|
214
222
|
self._sync_lock: Final[Lock] = got[1]
|
|
215
223
|
self._instance_lock: Final[Lock] = Lock() # Allow multiple threads to use this instance at once
|
|
@@ -237,7 +245,7 @@ class _IPLock(AbstractIPLock):
|
|
|
237
245
|
acquired = self.acquired
|
|
238
246
|
if acquired and not self._instance_reentrant:
|
|
239
247
|
if timeout_per is None:
|
|
240
|
-
raise
|
|
248
|
+
raise LockHungError(f"{self.__class__.__name__}: {self.path}")
|
|
241
249
|
return ret
|
|
242
250
|
timeout = -1 if timeout_per is None else timeout_per
|
|
243
251
|
if acquired or self._sync_lock.acquire(blocking, timeout=timeout):
|
|
@@ -253,7 +261,7 @@ class _IPLock(AbstractIPLock):
|
|
|
253
261
|
"""Release the lock"""
|
|
254
262
|
with self._instance_lock:
|
|
255
263
|
if not self.acquired:
|
|
256
|
-
raise
|
|
264
|
+
raise NotAcquiredError(f"{self.__class__.__name__}: {self.path}")
|
|
257
265
|
self._rc -= 1
|
|
258
266
|
if self._rc == 0:
|
|
259
267
|
try:
|
|
@@ -264,7 +272,7 @@ class _IPLock(AbstractIPLock):
|
|
|
264
272
|
raise
|
|
265
273
|
try:
|
|
266
274
|
self._gipl.release()
|
|
267
|
-
except
|
|
275
|
+
except NotAcquiredError as e:
|
|
268
276
|
raise OSError("The GlobalIPLock lock was already unlocked by something else") from e
|
|
269
277
|
|
|
270
278
|
|
|
@@ -4,10 +4,10 @@ from collections.abc import Hashable
|
|
|
4
4
|
from abc import ABCMeta
|
|
5
5
|
import sys
|
|
6
6
|
|
|
7
|
-
__all__ = ("
|
|
7
|
+
__all__ = ("CircularConstructionError", "KeyedInstance", "KeyedInstanceProcessError")
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
class
|
|
10
|
+
class CircularConstructionError(RuntimeError):
|
|
11
11
|
"""Raised when keyed constructors form a circular dependency."""
|
|
12
12
|
|
|
13
13
|
def __init__(self, type_: type) -> None:
|
|
@@ -101,7 +101,7 @@ class _KeyedInstanceMeta(ABCMeta):
|
|
|
101
101
|
break
|
|
102
102
|
blocking = dependency.tid
|
|
103
103
|
else:
|
|
104
|
-
raise
|
|
104
|
+
raise CircularConstructionError(cls)
|
|
105
105
|
|
|
106
106
|
# Wait for a thread to finish construction then recheck if we can start
|
|
107
107
|
condition.wait()
|
|
@@ -139,7 +139,7 @@ class KeyedInstance(metaclass=_KeyedInstanceMeta):
|
|
|
139
139
|
The first thread to claim a cache key performs construction. If
|
|
140
140
|
construction fails, another waiting thread can attempt construction.
|
|
141
141
|
|
|
142
|
-
If items being constructed require constructing each other, a
|
|
142
|
+
If items being constructed require constructing each other, a CircularConstructionError is raised
|
|
143
143
|
|
|
144
144
|
Do not mix this with fork (uses thread ids internally); multiprocessing spawn is ok
|
|
145
145
|
"""
|
|
@@ -2,13 +2,16 @@ from collections.abc import Callable, Iterator
|
|
|
2
2
|
from contextlib import contextmanager
|
|
3
3
|
from logging import getLogger
|
|
4
4
|
from types import FrameType
|
|
5
|
+
from typing import Any
|
|
5
6
|
import signal
|
|
6
7
|
|
|
8
|
+
__all__ = ("signal_cm",)
|
|
9
|
+
|
|
7
10
|
|
|
8
11
|
@contextmanager
|
|
9
12
|
def signal_cm(
|
|
10
13
|
signalnum: signal.Signals | int,
|
|
11
|
-
handler: signal.Handlers | Callable[[int, FrameType | None],
|
|
14
|
+
handler: signal.Handlers | Callable[[int, FrameType | None], Any],
|
|
12
15
|
*,
|
|
13
16
|
disable_logging: bool = False,
|
|
14
17
|
) -> Iterator[None]:
|
|
@@ -3,6 +3,8 @@ from collections import defaultdict
|
|
|
3
3
|
from threading import RLock
|
|
4
4
|
from functools import cache
|
|
5
5
|
|
|
6
|
+
__all__ = ("NoInstanceError", "Singleton")
|
|
7
|
+
|
|
6
8
|
|
|
7
9
|
class NoInstanceError(TypeError):
|
|
8
10
|
"""A TypeError raised when trying to get a Singleton instance before constructing it"""
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|