python popen timeout_python subprocess.Popen 运行多进程的 shell 写文件导致覆盖如何解决...

3

2015-06-08 11:06:57 +08:00

@henryon

由于原始的比较复杂些,我简单写了个例子

我先写了个python 然后运行shell 然后运行awk 内容如下:

test.py

import veasyprocess

import os

cmd = "sh writefile.sh"

PWD = os.getcwd()

#veasyprocess模块中使用的就是subprocess.Popen方法,只是封装了下面两行

#fout=tempfile.TemporaryFile()

#subprocess.Popen(args=self.cmd.encode('utf-8'), stdout=self.stdout, stderr=self.stderr, shell=True, cwd=self.cwd)

status, outs = veasyprocess.shell_2_tempfile(_cmd = cmd, _cwd = PWD, _timeout = 240)

print status

print outs

============================================

wirtefile.sh

for((i=0; i<10; i++)); do

{

awk -f error.awk writefile.sh

}&

done

wait

error.awk

END {

for(i=0; i<10000; i++) {

printf "hello world 11111 22222 33333 44444 55555 66666\n"

}

}

~

输出内容有下面这种

hello world 11111 22222 33333 44444 55555 66666

1 22222 33333 44444 55555 66666

hello world 11111 22222 33333 44444 55555 66666

hello world 11111 22222 33333 44444 55555 66666

hello world 11111 22222 33333 44hello world 11111 22222 33333 44444 55555 66666

hello world 11111 22222 33333 44444 55555 66666

输出的内容明显有覆盖现象,要达到的效果就是数据无覆盖,即每行都是完整的hello world 11111 22222 33333 44444 55555 66666

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值