Python:为什么我的 SMTP 脚本冻结了我的计算机?
所以我写了一个小的多线程 SMTP 程序。问题是每次我运行它时,它都会很快冻结计算机。该脚本似乎仍然有效,因为我的网卡仍然亮着并且收到了电子邮件,但在某些情况下它会完全锁定并停止发送电子邮件。
这是我的两个脚本文件的链接。第一个是用于启动程序的:
So I wrote a little multithreaded SMTP program. The problem is every time I run it, it freezes the computer shortly after. The script appears to still work, as my network card is still lighting up and the emails are received, but in some cases it will lock up completely and stop sending the emails.
Here's a link to my two script files. The first is the one used to launch the program:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,您使用
popen
创建子流程,即。进程而不是线程。我假设这就是你的意思。我的猜测是,程序陷入了不断生成进程的循环中,操作系统可能会不喜欢这种情况。 (这种东西被称为forkbomb,这是冻结 Linux 的好方法,除非进程限制已使用
ulimit
设置。)虽然我找不到该错误,但如果我是你,我会在每次生成或终止子进程时记录消息,如果一切正常,密切观察系统(Unix 系统上的ps
或top
)查看进程是否真的被杀死。First, you're using
popen
which creates subprocesses, ie. processes not threads. I'll assume this is what you meant.My guess would be that the program gets stuck in a loop where it generates processes continuously, which the OS will probably dislike. (That kind of thing is known as a forkbomb which is a good way to freeze Linux unless a process limit has been set with
ulimit
.) I couldn't find the bug though, but if I were you, I'd log messages each time I spawn or kill a subprocess, and if everything is normal, watch the system closely (ps
ortop
on Unix systems) to see if the processes are really being killed.