ThreadCam
A zero-lag, ultra-low-latency threaded camera multiplexer for Python.
Are you building a Flask app that streams video? Are you running a Machine Learning inference loop that drops frames or causes your UI to stutter?
ThreadCam completely eliminates OpenCV's VideoCapture IO bottleneck.
The Problem
When you call cap.read() in OpenCV, your Python script completely blocks while waiting for the USB hardware to compress and deliver the frame buffer. If you try to run multiple generators (like streaming to a Web UI and running an ML model), they fight for the camera lock, causing massive lag and crashes.
The Solution
ThreadCam opens your webcam exactly once in a dedicated, ultra-light background C-thread. It constantly maintains the absolute latest frame in RAM behind a thread-safe lock.
You can have infinite Python consumers reading .read() simultaneously. Because they are pulling from RAM instead of the hardware buffer, it executes in exactly 0.0000ms, completely unblocking your application loop.
Installation
pip install ThreadCam
Usage
from ThreadCam import ThreadCam
import cv2
# Initialize the hub (Starts the background thread)
hub = ThreadCam(src=0, target_fps=30)
while True:
# Read the absolute newest frame instantly from RAM
ret, frame = hub.read()
if not ret:
continue
cv2.imshow("ThreadCam", frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
hub.stop()
Ideal Use Cases
- Flask / FastAPI MJPEG Streaming
- MediaPipe / YOLO Inference Engines
- PyGame / Tkinter UI Overlays
- Multi-threaded processing pipelines
Release files for ThreadCam 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| threadcam-0.1.0.tar.gz | 3.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| threadcam-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 6.9 kB
Release files / threadcam-0.1.0.tar.gz
| Download URL | threadcam-0.1.0.tar.gz |
|---|---|
| Size | 3.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7ac89a9c8be9dc0c5a16b86f972019862e06d8b10d7b9dd665aa9a2cc78dbe7d
|
|
BLAKE2b-256 checksum How to use checksums |
9d805368dec6a9345d55dd35e67ba5646c6d2c1b999c86a30748a52f6e5437f5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.9
|
Release files / threadcam-0.1.0-py3-none-any.whl
| Download URL | threadcam-0.1.0-py3-none-any.whl |
|---|---|
| Size | 3.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3fa8c7145b4f507034acc71630ccf7203393f63cb4fc906adf8a2d4245f89a97
|
|
BLAKE2b-256 checksum How to use checksums |
e373a4f48b0933ecd844b61bd3c1c13f562e26d601b1cdd8c012dcfa2215b889
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.9
|