Sending many signals to a Python process crashes the interpreter
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 36k
- PR 合并指标
- PR 指标待抓取
描述
Bug report
Bug description:
Consider the following simple program (test-breakage.py):
from time import sleep
import os
import signal
class Foreman:
def __init__(self):
signal.signal(signal.SIGUSR1, self.handle_sigusr1)
pid = os.getpid()
print("Test script created, my pid is %s", pid)
with open("/tmp/test-breakage.pid", "w") as f:
f.write(str(pid))
def handle_sigusr1(self, sig, frame):
print("handle_sigusr1")
def run_forever(self):
sleep(3600)
Foreman().run_forever()
Now, a tool to send "a lot" of signal to it:
import os
import sys
import signal
pid = int(sys.argv[1])
iterations = int(sys.argv[2])
for i in range(iterations):
os.kill(pid, signal.SIGUSR1)
Or, if you want the signals to be sent more quickly, implemented in c:
#include <stdlib.h>
#include <signal.h>
int main(int argc, char*argv[]) {
long pid, iterations;
if (argc > 2) {
pid = strtol(argv[1], NULL, 0);
iterations = strtol(argv[2], NULL, 0);
for (int i = 0; i < iterations; i++) {
kill(pid, SIGUSR1);
}
}
return 0;
}
Running these scripts with "sufficiently high" numbers results in various crashes in test-breakage
- Exit with "User defined signal 1" (shouldn't happen, we've defined a handler)
RuntimeErrorwithout any further information- Exit without any printed string
- RuntimeError: reentrant call inside <_io.BufferedWriter name=''>
(In all cases, after repeating "handle_sigusr1" a number of times first)
tested on Linux w. Python 3.10
CPython versions tested on:
3.10
Operating systems tested on:
Linux
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
Start by reproducing the failure with the test-breakage.py signal handler and the Python or C signal-sending scripts on Linux. Compare the reported outcomes under sustained SIGUSR1 delivery; done means the interpreter remains stable and the registered handler continues to behave correctly without the listed crashes or unintended termination.
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- operating-systems
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 42/100