
Security News
The Nightmare Before Deployment
Season’s greetings from Socket, and here’s to a calm end of year: clean dependencies, boring pipelines, no surprises.
redisrwlock
Advanced tools
Distributed reader-writer lock for python using redis as server
Features:
python3 -m redisrwlock)Note: Deadlock detection and garbage/staleness collection is done in
client side, which can cause excessive I/O with redis server. Tune
with retry_interval and consider running the stale lock collection
appropriately for your purpose.
Dependencies:
.. code-block:: console
pip install redisrwlock
With timeout=0, RwlockClinet.lock acts as so called try_lock.
.. code-block:: python
from redisrwlock import Rwlock, RwlockClient
client = RwlockClient() rwlock = client.lock('N1', Rwlock.READ, timeout=0) if rwlock.status == Rwlock.OK: # Processings of resource named 'N1' with READ lock # ... client.unlock(rwlock) elif rwlock.status == Rwlock.FAIL: # Retry locking or quit
With timout > 0, RwlockClient.lock waits until lock successfully or deadlock detected and caller is chosen as victim.
.. code-block:: python
from redisrwlock import Rwlock, RwlockClient
client = RwlockClient() rwlock = client.lock('N1', Rwlock.READ, timeout=Rwlock.FOREVER) if rwlock.status == Rwlock.OK: # Processings of resource named 'N1' with READ lock # ... client.unlock(rwlock) elif rwlock.status == Rwlock.DEADLOCK: # 1. unlock if holding any other locks # 2. Retry locking or quit
When a client exits without unlock, redis keys for the client's locks
remain in server and block other clients from successful locking.
redisrwlock run in command line removes such garbage locks, waits
in server.
.. code-block:: console
python3 -m redisrwlock
You can repeat this gc periodically by specifying -r or --repeat option.
Runnig unittest in test directory:
.. code-block:: console
cd test python3 -m unittest -q
or in project top directory:
.. code-block:: console
python3 -m unittest discover test -q
Examples below are assuming you run unittest in project top directory.
.. code-block:: console
coverage erase coverage run -a -m unittest discover test -q coverage html
Above simple coverage run will report lower coverage than expected because the tests use subprocess. Codes run by subprocess are not covered in report by default.
Need some preperation:
Edit sitecustomize.py (under python intallation's site-packages
directory), add 2 lines
.. code-block:: python
import coverage coverage.process_startup()
Edit .coveragerc (default name of coverage.py's config file)
.. code-block:: cfg
[run] branch = True [html] directory = htmlcov
Then, run coverage with environment variable
COVERAGE_PROCESS_START={path/to/coveragerc}
.. code-block:: console
coverage erase COVERAGE_PROCESS_START=.coveragerc coverage run -a -m unittest discover test -q coverage html
FAQs
Distributed reader-writer lock (rwlock) for python using redis
We found that redisrwlock demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Season’s greetings from Socket, and here’s to a calm end of year: clean dependencies, boring pipelines, no surprises.

Research
/Security News
Impostor NuGet package Tracer.Fody.NLog typosquats Tracer.Fody and its author, using homoglyph tricks, and exfiltrates Stratis wallet JSON/passwords to a Russian IP address.

Security News
Deno 2.6 introduces deno audit with a new --socket flag that plugs directly into Socket to bring supply chain security checks into the Deno CLI.