-
-
Notifications
You must be signed in to change notification settings - Fork 226
fix: instead of burning 100% CPU in a endless loop, use threading.Event #926
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideThis PR replaces a CPU-intensive busy-wait loop with threading.Event for graceful signal handling and updates the otel-gpu-collector Dockerfile to use a newer base image, install additional dependencies, reorder build steps, and simplify package installation. Sequence diagram for signal handling with threading.EventsequenceDiagram
participant Collector as "collector.py"
participant OS as "Operating System"
participant Logger
Collector->>OS: Wait for termination signal
OS-->>Collector: Send termination signal (SIGINT/SIGTERM)
Collector->>Logger: Log "Received termination signal"
Collector->>Collector: Set keep_running Event
Collector->>Collector: keep_running.wait() returns, script exits
Class diagram for signal handling logic updateclassDiagram
class collector_py {
- keep_running: Event
+ signal_handler(sig, frame)
+ main()
}
collector_py : signal_handler sets keep_running Event
collector_py : main() waits on keep_running Event
File-Level Changes
Assessment against linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey there - I've reviewed your changes - here's some feedback:
- In the Dockerfile, pin your Python dependencies (or use a requirements.txt) instead of installing latest for reproducible builds and to avoid unexpected breakage.
- Reorder your Dockerfile to leverage layer caching: COPY only your requirements first, run pip install, then COPY the rest of your source.
- In collector.py, explicitly import threading.Event at the top, consider renaming
keep_runningto something likestop_event, and drop the unnecessaryglobalsince Event is mutable.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In the Dockerfile, pin your Python dependencies (or use a requirements.txt) instead of installing latest for reproducible builds and to avoid unexpected breakage.
- Reorder your Dockerfile to leverage layer caching: COPY only your requirements first, run pip install, then COPY the rest of your source.
- In collector.py, explicitly import threading.Event at the top, consider renaming `keep_running` to something like `stop_event`, and drop the unnecessary `global` since Event is mutable.
## Individual Comments
### Comment 1
<location> `otel-gpu-collector/dockerfile:8-17` </location>
<code_context>
# Install build dependencies and necessary libraries
RUN apt-get update && apt-get install -y --no-install-recommends \
gcc \
+ build-essential \
python3-dev \
libffi-dev \
</code_context>
<issue_to_address>
**suggestion:** Evaluate necessity of both 'gcc' and 'build-essential' in the image.
Consider removing 'gcc' to avoid redundancy and minimize image size and installation time.
```suggestion
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
python3-dev \
libffi-dev \
libssl-dev \
amd-smi \
libamd-smi-dev \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
… wait and notify when signal is caught (cherry picked from commit 90be483)
b1bb881 to
08b42ec
Compare
|
Thanks @phueper for the fix! |
to wait and notify when signal is caught
fixes #925
(cherry picked from commit 90be483)
Important
feat: ...orfix: ....#925:
Change description:
instead of burning 100% CPU in a endless loop, use threading.Event to wait and notify when signal is caught
Checklist
If your change doesn't seem to apply, please leave them unchecked.
feat: ...orfix: ....Acknowledgment
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of the project license.
Summary by Sourcery
Implement efficient shutdown signaling in the GPU collector and optimize its Docker image build
Bug Fixes:
Enhancements: