Python bindings (pybind11) — Phase 0 v1 #7
Reference in New Issue
Block a user
Delete Branch "feat/python-bindings"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Закрывает #6.
Что внутри
Полный subscriber-side wrapper над cuframes C ABI:
CuframesSubscriber+CuframesFrame— RAII-классы, оба context managersframe.dlpack_y(),frame.dlpack_uv(),frame.__dlpack__()для PyTorch/CuPy zero-copyconsumer_stream(cudaStream_t как int)frames_received,timeouts,errors,last_seq,gap_count,stats()dictCuframesError+ 8 subclasses, маппинг черезexception_for(int err)subscriber_create,next_frame)Сборка и тесты
Wheel:
Что не вошло в Phase 0
ring_occupancy/ drop counter из C API — counted в pybind какgap_count(proxy для NEWEST_ONLY mode)Документация
docs/python.md(~250 строк): quick start, API reference, integration с PyTorch / CuPy, reconnect-loop pattern, per-stream usage, pitch alignment важности, thread-safety, error taxonomy, backpressure, Phase 0 limitations.Архитектурный контекст
Это блокирующая dep для
goldix-smart-home/yolo-world-detectorPhase 1 (open-vocabulary object detector — параллельный consumer cuframes). Архитектор подтвердил подход «pybind first, не ctypes shortcut» — иначе 2 incompatible Python entry points в core lib.См. также:
py::exception<T>(...) уже возвращает Python class object. Дополнительный .attr("__class__") давал metaclass (type), из-за чего issubclass() проверка для всех subexc возвращала False. Verify: pytest tests/test_smoke.py — 5/5 passed. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>Реализует subscriber-side wrapper над cuframes_subscriber_* и cuframes_frame_* C API. Что добавлено: - CuframesFrame — owning RAII wrapper над cuframes_frame_t* - properties: cuda_ptr, format, width, height, pitch_y, pitch_uv, seq, pts_ns, released - release() idempotent - context manager (__enter__/__exit__) — release при выходе - после release() property access бросает CuframesError - CuframesSubscriber — owning RAII wrapper над cuframes_subscriber_t* - конструктор с key/consumer_name/mode/cuda_device/connect_timeout_ms - next_frame(timeout_ms) → CuframesFrame - close() idempotent - context manager - GIL released на блокирующих вызовах (create, next_frame) - subscribe() — module-level factory shortcut Архитектурные решения: - GIL release в py::gil_scoped_release на subscriber_create и _next — чтобы другие Python потоки могли работать пока ждём frame - consumer_stream передаётся как nullptr в Phase 0 (default stream); per-subscriber stream в task #201 - Frame держит raw pointer на subscriber, refcount Python-стороной; если subscriber уничтожен раньше, frame.release() становится no-op Smoke tests расширены до 8 — добавлены проверки exposed API и error mapping на subscribe к несуществующему publisher'у. Verify: pytest tests/test_smoke.py — 8/8 passed. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>