Skip to content

Commit abfd0ab

Browse files
walter201230claude
andcommitted
fix: 收尾 CI 剩余三处失败——Event 竞态加 timeout,两个 3.12+ 语法块加 skip
73e0e7d 推送后 CI 仍红,四个版本失败数 3.10=2 / 3.11=3 / 3.12=0 / 3.13=1。 差异全部来自版本语法特性,不再是此前的环境抖动(stdin 与超时已在上一个 commit 修掉),说明那次修复方向是对的,只是我的本地验证没覆盖到。 三处失败逐个对应处理: - python13/2.md 的 Event 示例(3.11 与 3.13 触发 timeout):`if event.isSet()` 与 `event.clear()` 之间不是原子操作,两个线程可能都通过判断、都进 wait(), 而只有一个 set() 来唤醒,剩下那个永久阻塞。改为 event.wait(timeout=1), 即使竞态触发也必定在 1 秒后返回。这是逻辑兜底而非降低概率。本地连跑 30 次 全部正常、最长 0.02 秒(正常路径不会真等满 1 秒)。 - python2/Type_of_data.md:442 与 python6/3.md:422(3.10 与 3.11 触发 SyntaxError):分别是 PEP 701 的 f-string 内嵌同类引号、PEP 695 的 type 语句,都需要 3.12+。两处正文本就写明「Python 3.12+」,前者甚至明说 「在 3.11 及之前是错的」——它们在低版本失败正是教程要表达的事实,不是 错误,故加 skip-ci。没有为此给 example_runner 扩「最低版本」标记机制: 只有 2 个块受影响且正文已用文字说明,不值当。 验证方法的修正(上一轮就栽在这里):本机只有 Python 3.14,CI 跑 3.10~3.13, 「本地全绿」推不出「CI 会绿」。本轮改用 ast.parse(code, feature_version=...) 对 491 个未 skip 块 × 四个版本做语法检查,0 处不兼容,不必装多版本 Python。 运行时层面的版本差异本地仍测不出,最终以 CI 为准。 本地全量:总计 691 块;跳过 200;失败 0;exit 0。 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EKcB6SFyeRo9UPJL99QvkC
1 parent 73e0e7d commit abfd0ab

3 files changed

Lines changed: 5 additions & 1 deletion

File tree

‎Article/PythonBasis/python13/2.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,9 @@ class mThread(threading.Thread):
352352
# 判断Event对象内部信号标志
353353
if event.isSet():
354354
event.clear()
355-
event.wait()
355+
# 加 timeout 兜底:isSet() 判断与 clear() 之间不是原子操作,
356+
# 两个线程可能都通过判断、都进 wait(),而只有一个 set() 来唤醒
357+
event.wait(timeout=1)
356358
print(self.getName())
357359
else:
358360
print(self.getName())

‎Article/PythonBasis/python2/Type_of_data.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,7 @@ print(f'转化率:{rate:.1%}')
439439

440440
比如下面这种写法,在 3.11 及之前是 **错的** :
441441

442+
<!-- skip-ci -->
442443
```python
443444
data = {'name': '两点水', 'age': 18}
444445

‎Article/PythonBasis/python6/3.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,7 @@ User(name='两点水', age=18, sex='女')
419419
420420
最后再提一个 Python 3.12 的新东西(PEP 695)。如果你写了一个特别长的复合类型,每次都重复写不优雅,可以用 `type` 关键字给它起个别名:
421421

422+
<!-- skip-ci -->
422423
```python
423424
type UserId = int | str
424425
type PhoneBook = dict[str, str]

0 commit comments

Comments
 (0)