-
Notifications
You must be signed in to change notification settings - Fork 179
Feat/timer #1400
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
Feat/timer #1400
Conversation
Introduced a new Timer utility in swanlab.core_python.utils for scheduled and repeated task execution using daemon threads and event signaling. Added comprehensive unit tests for Timer, updated requirements-dev.txt to include pytest-mock, and adjusted __init__.py imports to expose the new utility.
Replaced MonitorCron with timer.Timer and a new monitor_interval function for hardware monitoring in SwanLabRun. Removed the check_log_level utility and its test, simplifying helper.py and cleaning up related test code. Also commented out problematic imports in __init__.py to avoid circular dependencies.
Summary of ChangesHello @SAKURA-CAT, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! 此拉取请求重构了项目中的定时器功能,引入了一个更通用、更健壮的 Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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.
Code Review
本次 PR 对定时器部分进行了重构,封装了一个通用的 Timer 类,这是一个非常好的改进。新的 Timer 类设计清晰,支持固定和动态间隔,并且通过 threading.Event 实现了可靠的停止机制,还考虑了任务执行过程中的异常处理,整体上是健壮和灵活的。
代码库中原有的 MonitorCron 被新的 Timer 替代,使得相关代码 (swanlab/data/run/main.py) 更加简洁。
此外,为新的 Timer 类添加了全面的单元测试 (test/unit/core_python/utils/test_timer.py),覆盖了各种场景,这极大地保证了新模块的质量和稳定性。
我只发现了一个小问题,关于 Timer 类中一个似乎不必要的锁,具体见我的评论。总体来说,这是一次高质量的重构。
Eliminated the threading.Lock previously used for mutual exclusion in the Timer class, as it was not necessary for task execution. The task execution method now directly calls the task without lock protection.
Description
重构了定时器部分代码,现在封装了一个更通用的定时器类型,为 #1255 做准备