You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+61-84Lines changed: 61 additions & 84 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,7 +15,7 @@ pip install etcd_client
15
15
16
16
```python
17
17
from etcd_client import EtcdClient
18
-
etcd = EtcdClient(['http:://127.0.0.1:2379'])
18
+
etcd = EtcdClient(['http://127.0.0.1:2379'])
19
19
```
20
20
21
21
Actual connection establishment with Etcd's gRPC channel will be done when you call `EtcdClient.connect()`.
@@ -28,28 +28,9 @@ async def main():
28
28
print(bytes(value).decode()) # testvalue
29
29
```
30
30
31
-
### Cleanup on shutdown
31
+
### Working with key prefixes
32
32
33
-
To prevent segfaults or GIL state violations during Python interpreter shutdown, you should call `cleanup_runtime()` at the end of your main async function before the event loop shuts down:
34
-
35
-
```python
36
-
from etcd_client import EtcdClient, cleanup_runtime
# Runtime automatically cleaned up when context exits
68
+
69
+
asyncio.run(main())
70
+
```
71
+
72
+
The library uses reference counting to track active client contexts. When the last context exits, the tokio runtime is gracefully shut down, waiting up to 5 seconds for pending tasks to complete. If you create new clients after this, the runtime is automatically re-initialized.
73
+
74
+
For advanced use cases requiring explicit control, `cleanup_runtime()` is available:
75
+
76
+
```python
77
+
from etcd_client import cleanup_runtime
78
+
79
+
# Force cleanup at a specific point (usually not needed)
80
+
cleanup_runtime()
81
+
```
82
+
72
83
## Operating with Etcd lock
73
84
74
-
Just like `EtcdClient.connect()`, you can easilly use etcd lock by calling `EtcdClient.with_lock(lock_opts)`.
85
+
Just like `EtcdClient.connect()`, you can easily use etcd lock by calling `EtcdClient.with_lock(lock_opts)`.
75
86
76
87
```python
77
88
asyncdeffirst():
@@ -98,18 +109,11 @@ async with etcd.connect() as communicator:
You can run etcd transaction by calling `EtcdCommunicator.txn(txn)`.
211
+
You can run etcd transactions by calling `EtcdCommunicator.txn(txn)`.
208
212
209
213
### Constructing compares
210
214
211
-
Constructing compare operations can be done by comparing`Compare`instance.
215
+
Constructing compare operations can be done using the`Compare`class.
212
216
213
217
```python
214
218
from etcd_client import Compare, CompareOp
@@ -218,7 +222,7 @@ compares = [
218
222
]
219
223
```
220
224
221
-
### Executing transaction calls
225
+
### Executing transactions
222
226
223
227
```python
224
228
asyncwith etcd.connect() as communicator:
@@ -232,29 +236,26 @@ async with etcd.connect() as communicator:
232
236
]
233
237
234
238
res =await communicator.txn(Txn().when(compares).and_then([TxnOp.get('successkey'.encode())]))
235
-
print(res) #TODO: Need to write response type bindings.
239
+
print(res) #TODO: Need to write response type bindings.
236
240
```
237
241
238
242
## How to build
239
243
240
-
### Prerequisite
244
+
### Prerequisites
241
245
242
-
* The Rust development environment (the 2021 edition or later) using [`rustup`](https://rustup.rs/) or your package manager
246
+
* The Rust development environment (2021 edition or later) using [`rustup`](https://rustup.rs/) or your package manager
243
247
* The Python development environment (3.10 or later) using [`pyenv`](https://github.com/pyenv/pyenv#installation) or your package manager
244
248
245
-
### Build instruction
249
+
### Build instructions
246
250
247
-
First, create a virtualenv (either using the standard venv package, pyenv, or
248
-
whatever your favorite). Then, install the PEP-517 build toolchain and run it.
251
+
First, create a virtualenv (using the standard venv package, pyenv, or your preferred tool). Then, install the PEP-517 build toolchain and run it.
249
252
250
253
```shell
251
254
pip install -U pip build setuptools
252
255
python -m build --sdist --wheel
253
256
```
254
257
255
-
It will automatically install build dependencies like
256
-
[`maturin`](https://github.com/PyO3/maturin) and build the wheel and source
257
-
distributions under the `dist/` directory.
258
+
This will automatically install build dependencies like [`maturin`](https://github.com/PyO3/maturin) and build the wheel and source distributions under the `dist/` directory.
258
259
259
260
## How to develop and test
260
261
@@ -279,42 +280,18 @@ uv run maturin develop # Builds and installs the Rust extension
279
280
This project uses ruff for linting/formatting and mypy for type checking:
0 commit comments