关于storm-0.8.2框架与github中storm-starter工程不兼容的疑问

博客内容涉及到在使用storm-0.8.2框架时遇到与github上的storm-starter工程不兼容的问题。具体表现为ShellProcess类的launch方法期望接收到JSON格式的PID,而storm-starter的python代码仅回写PID。作者通过修改storm.py,使其返回符合期望的JSON格式解决了报错,但对不同storm版本间的不一致感到困惑。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在storm-0.8.2中ShellProcess.class文件中,存在这样的一段代码:
public class ShellProcess {
    .....
    public Number launch(Map conf, TopologyContext context) throws IOException {
        ......
         return (Number)readMessage().get("pid");
    }

这段代码的意思是启动外部进程,并获得其PID。而且是Json格式获得的,意味着,希望外部进程通过管道返回
{"pid"=12345}类似的消息。

但我查看了storm-starter project中python写的storm.py代码
原代码:
def sendpid(heartbeatdir):
    pid = os.getpid()
     print pid
    sys.stdout.flush()
    open(heartbeatdir + "/" + str(pid), "w").close()  
这表示如果启动的外部进程PID是12345,仅仅向管道中回写12345.

这会导致storm-starter启动时,报错如下:
java.lang.RuntimeException:  Pipe to subprocess seems to be broken! Currently read output: 22226
Shell Process Exception:
Traceback (most recent call last):
  File "splitsentence.py", line 9, in <module>
    SplitSentenceBolt().run()
  File "/tmp/b43b4e11-bc3a-4913-87cd-9a76ae5a33c7/supervisor/stormdist/word-count-1-1372691252/resources/storm.py", line 127, in run
    conf, context = initbolt()
.....

我根据理解,修改了storm.py内容如下,总算不报错了,但绝对很奇怪,为什么明显的不一致?
def sendpid(heartbeatdir):
    pid = os.getpid()
    print "{\"pid\":"+str(pid)+"}"
    print "end"
    sys.stdout.flush()
    open(heartbeatdir + "/" + str(pid), "w").close()  

看了storm-0.7.0的代码和0.8.2的代码不一致,是可以正常运行storm-starter
正在请教专家解决。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值