来.各位帮我看看我的代码哪儿错了吧.搞不懂诶.

164 views
Skip to first unread message

Stduolc X

unread,
Sep 27, 2017, 7:31:38 AM9/27/17
to python-cn(华蟒用户组,CPyUG 邮件列表)
https://gist.github.com/stduolc/19b0efd0f794ff62ee9b1b05de5b9841/revisions

这个代码.子进程应该在收到SIGPIPE的时候直接退出了.但是结果他一直活着的.然后把磁盘IO吃了好多.咋搞啊?

依云

unread,
Sep 27, 2017, 10:11:32 AM9/27/17
to pyth...@googlegroups.com
On Wed, Sep 27, 2017 at 04:31:37AM -0700, Stduolc X wrote:
> https://gist.github.com/stduolc/19b0efd0f794ff62ee9b1b05de5b9841/revisions
>
> 这个代码.子进程应该在收到SIGPIPE的时候直接退出了.但是结果他一直活着的.然后把磁盘IO吃了好多.咋搞啊?

你的 tail 版本是多少?我这里测试结果是:Python 3 正常结束。Python
2 下 tail 会报错,写 stderr 失败(EPIPE),然后继续报错,还是写失败,然
后不管了直接退出。

因为在 initsigs 函数中,Python 忽略了 SIGPIPE 等几个信号。Python
2 的 subprocess 没有处理,忽略行为被继承了;Python 3 的 subprocess
有 restore_signals 并默认为 True,恢复了那些信号的默认行为。

我的 tail 是 GNU coreutils 8.28 的。

话说要不上 Python 3 吧?Salt 已经支持 Python 3 了哦~

--
Best regards,
lilydjwg

Linux Vim Python 我的博客:
https://blog.lilydjwg.me/
--
A: Because it obfuscates the reading.
Q: Why is top posting so bad?

Stduolc X

unread,
Sep 28, 2017, 4:04:51 AM9/28/17
to python-cn(华蟒用户组,CPyUG 邮件列表)
还在想办法复现这个问题.我先下测试是通过了.
tail (GNU coreutils) 8.22
Python 2.7.5
昨天一个朋友和我说.建议把管道反过来`tail -f /legal/file/xxx.log | pipe2server.py $host $port` 这样就可以自己处理socket了.我觉得是个靠谱的方案.就是不知道python的socket处理性能怎么样.

在 2017年9月27日星期三 UTC+8下午10:11:32,依云写道:

依云

unread,
Sep 28, 2017, 6:06:38 AM9/28/17
to pyth...@googlegroups.com
On Thu, Sep 28, 2017 at 01:04:50AM -0700, Stduolc X wrote:
> 还在想办法复现这个问题.我先下测试是通过了.
> tail (GNU coreutils) 8.22
> Python 2.7.5
> 昨天一个朋友和我说.建议把管道反过来`tail -f /legal/file/xxx.log | pipe2server.py $host
> $port` 这样就可以自己处理socket了.我觉得是个靠谱的方案.就是不知道python的socket处理性能怎么样.

你自己在子进程里把 SIGPIPE 的行为恢复不就好了吗?

tail 的代码好复杂。8.22 还好,8.28 看上去无法处理 short write。

> tail -f /legal/file/xxx.log | pipe2server.py $host

为什么不用 socat 或者 nc 呢?

peng yu

unread,
Sep 29, 2017, 3:37:22 PM9/29/17
to pyth...@googlegroups.com
或者试试select? https://github.com/yupbank/RemoteTail 我以前写过一个好像是work的..

--
邮件来自: `CPyUG`华蟒用户组(中文Python技术邮件列表)
规则: http://code.google.com/p/cpyug/wiki/PythonCn
详情: http://code.google.com/p/cpyug/wiki/CpyUg
严正: 理解列表! 智慧提问! http://wiki.woodpecker.org.cn/moin/AskForHelp
---
您收到此邮件是因为您订阅了 Google 网上论坛的“python-cn(华蟒用户组,CPyUG 邮件列表)”群组。
要退订此群组并停止接收此群组的电子邮件,请发送电子邮件到python-cn+unsubscribe@googlegroups.com
要向此群组发帖,请发送电子邮件至 pyth...@googlegroups.com
要查看更多选项,请访问 https://groups.google.com/d/optout

Reply all
Reply to author
Forward
0 new messages