Skip to content

Commit b3cc720

Browse files
author
esblinov
committed
Add Test Your Locks section to README
1 parent ce31c97 commit b3cc720

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ It contains several useful additions to the standard thread synchronization tool
2020
- [**Installation**](#installation)
2121
- [**Lock protocols**](#lock-protocols)
2222
- [**SmartLock - deadlock is impossible with it**](#smartlock---deadlock-is-impossible-with-it)
23+
- [**Test your locks**](#test-your-locks)
2324

2425

2526
## Installation
@@ -171,3 +172,33 @@ If you want to catch the exception, import this from the `locklib` too:
171172
```python
172173
from locklib import DeadLockError
173174
```
175+
176+
177+
## Test your locks
178+
179+
Sometimes, when testing a code, you may need to detect if some action is taking place inside the lock. How to do this with a minimum of code? There is the `LockTraceWrapper` for this. It is a wrapper around a regular lock, which records it every time the code takes a lock or releases it. At the same time, the functionality of the wrapped lock is fully preserved.
180+
181+
It's easy to create an object of such a lock. Just pass any other lock to the class constructor:
182+
183+
```python
184+
from threading import Lock
185+
from locklib import LockTraceWrapper
186+
187+
lock = LockTraceWrapper(Lock())
188+
```
189+
190+
You can use it in the same way as the wrapped lock:
191+
192+
```python
193+
with lock:
194+
...
195+
```
196+
197+
Anywhere in your program, you can "inform" the lock that the action you need is being performed here:
198+
199+
```python
200+
with lock:
201+
...
202+
```
203+
204+
https://ru.wikipedia.org/wiki/%D0%9F%D1%80%D0%B0%D0%B2%D0%B8%D0%BB%D1%8C%D0%BD%D0%B0%D1%8F_%D1%81%D0%BA%D0%BE%D0%B1%D0%BE%D1%87%D0%BD%D0%B0%D1%8F_%D0%BF%D0%BE%D1%81%D0%BB%D0%B5%D0%B4%D0%BE%D0%B2%D0%B0%D1%82%D0%B5%D0%BB%D1%8C%D0%BD%D0%BE%D1%81%D1%82%D1%8C

0 commit comments

Comments
 (0)