在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
正在请教专家解决。