fix: 修复抽奖动画学号显示错误与单实例检测失败问题#215
Merged
chenjintang-shrimp merged 7 commits intoSECTL:masterfrom Apr 4, 2026
Merged
Conversation
确保抽奖结果中的学生ID能够正确从候选数据中提取并传递到奖品信息中 同时修正抽奖结果显示时学生ID的获取逻辑
当无法附加到共享内存时,增加服务器状态检测和资源清理逻辑 修复本地服务器启动失败时未清理残留socket的问题
在POSIX系统上,QSharedMemory在进程崩溃后不会自动清理残留的共享内存段 添加_cleanup_stale_shared_memory函数来检测并清理这些残留资源
修复服务器无响应检查的描述不准确问题,改为更明确的"服务器不可连接" 改进奖品ID处理逻辑,增加异常捕获和多种ID字段尝试
通过ruff移除未使用的time导入
统一文档中的换行格式,移除多余的空格
Contributor
There was a problem hiding this comment.
Pull request overview
该 PR 修复了抽奖动画期间“学号/编号”显示与实际学生范围不一致的问题,并增强了应用在异常退出后重启时的单实例检测与本地 IPC 服务恢复能力;同时清理了已废弃的依赖文件与少量格式问题。
Changes:
- 抽奖动画帧生成时为随机候选人补充并优先使用
student_id,避免动画显示越界编号(Fixes #211)。 - 单实例检测在共享内存异常时增加服务器存活探测与残留资源清理,并在本地服务器监听失败时自动清理残留 socket 后重试。
- 删除冗余的
requirements-*.txt,并做少量导入/Markdown 格式清理。
Reviewed changes
Copilot reviewed 5 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| app/common/lottery/lottery_manager.py | 动画随机帧携带并优先展示学生 ID,修复动画期间编号越界显示。 |
| app/core/single_instance.py | 增强共享内存/本地服务器异常场景下的单实例检测与残留资源清理恢复逻辑。 |
| app/common/music/music_player.py | 移除未使用导入并做格式化调整。 |
| requirements-windows.txt | 删除冗余依赖文件(项目已迁移至 pyproject.toml/uv.lock)。 |
| requirements-linux.txt | 删除冗余依赖文件(项目已迁移至 pyproject.toml/uv.lock)。 |
| CHANGELOG/v2.3.5/CHANGELOG.md | 修正 Markdown 列表缩进/格式。 |
| CHANGELOG/v2.3.2/CHANGELOG.md | 修正 Markdown 列表缩进/格式。 |
| app/view/AGENTS.md | 清理多余空白行格式。 |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
chenjintang-shrimp
approved these changes
Apr 4, 2026
Contributor
chenjintang-shrimp
left a comment
There was a problem hiding this comment.
审核完毕,整体没有码风问题
质量很高,值得点赞
但是请注意文件行尾分隔符(lf/crlf)问题以避免造成不必要的git diff
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
修复内容
本 PR 包含两个独立的 bug 修复:
1. 修复抽奖动画期间学号显示错误 (Fixes #211 )
问题描述:
在播放抽奖动画时,截图抓拍显示的学号超出了班级实际人数范围(如显示70号,但班里一共56人)。
根本原因:
lottery_manager.py中的draw_random函数在创建动画帧数据时,错误地使用了奖品ID而非学生ID。当奖池中有70个奖品但班级只有56名学生时,动画显示的"学号"就会超出实际学生范围。修复方案:
get_random_items函数,在选取学生时同时获取并存储学生IDdraw_random函数,优先使用学生ID,当学生ID缺失或为0时回退到奖品ID影响范围:
2. 修复单实例检测与本地服务器启动失败 (initiative_1)
问题描述:
应用程序在异常终止后重启时出现两个相关问题:
根本原因:
当进程异常退出时,
QSharedMemory和QLocalServer的资源可能处于不一致状态,导致新进程无法正常启动。在POSIX系统(Linux/macOS)上,
QSharedMemory使用System V或POSIX共享内存API,这些系统级资源在进程崩溃后不会自动清理,导致重启时shared_memory.create(1)失败。修复方案:
_check_server_alive函数检测本地服务器是否可连接(仅检测连接性,不验证数据响应)_cleanup_stale_resources函数清理残留的socket资源_cleanup_stale_shared_memory函数清理残留的共享内存段(POSIX系统需要)check_single_instance函数,当无法附加共享内存时检测服务器状态setup_local_server函数,当 socket 地址被占用时清理残留资源后重试影响范围:
3. 删除冗余依赖文件
变更内容:
删除了
requirements-windows.txt和requirements-linux.txt两个依赖文件。原因:
项目已完全迁移到使用
pyproject.toml和uv.lock作为唯一的依赖来源,这两个文件不再需要。此变更是应项目成员@chenjintang-shrimp 要求进行。影响范围:
uv sync安装依赖修改文件
app/common/lottery/lottery_manager.pyapp/core/single_instance.pyapp/common/music/music_player.py(移除未使用的time导入)requirements-windows.txtrequirements-linux.txt测试建议
Issue #211 测试:
initiative_1 测试:
验证
所有修改已通过 ruff 代码检查。