【问题标题】:Python how to resolve the Error: java.lang.RuntimeException: PipeMapRed.waitOutputThreads(): subprocess failed with code 2Python 如何解决错误:java.lang.RuntimeException: PipeMapRed.waitOutputThreads(): subprocess failed with code 2
【发布时间】:2017-02-07 07:49:50
【问题描述】:

我在 hadoop 流中运行简单的 python 代码时遇到问题。 我已经尝试了以前帖子中的所有建议,但出现了类似的错误,但问题仍然存在。

  1. 添加了 usr/bin/env python
  2. chmod a+x mapper 和 reducer python 代码
  3. 为 -mapper “python mapper.py -n 1 -r 0.4”输入“”

我已经在外面运行了代码,它运行良好。

更新:我使用以下代码在 hadoop 流之外运行代码:

cat file |python mapper.py -n 5 -r 0.4 |sort|python reducer.py -f 3618 

这很好..但现在我需要将它运行到 HADOOP STREAMING

hadoop jar /usr/lib/hadoop-mapreduce/hadoop-streaming.jar \
-D mapreduce.job.reduces=5  \
-files lr \
-mapper "python lr/mapper.py -n 5 -r 0.4"  \
-reducer "python lr/reducer.py -f 3618"  \
-input training \
-output models 

hadoop 流是失败的。我查看了日志,但没有看到任何告诉我为什么会发生的信息?

我有以下 ma​​pper.py

#!/usr/bin/env python

import sys
import random

from optparse import OptionParser

parser = OptionParser()
parser.add_option("-n", "--model-num", action="store", dest="n_model",
                  help="number of models to train", type="int")
parser.add_option("-r", "--sample-ratio", action="store", dest="ratio",
                  help="ratio to sample for each ensemble", type="float")

options, args = parser.parse_args(sys.argv)

random.seed(8803)
r = options.ratio
for line in sys.stdin:
    # TODO
    # Note: The following lines are only there to help 
    #       you get started (and to have a 'runnable' program). 
    #       You may need to change some or all of the lines below.
    #       Follow the pseudocode given in the PDF.
    key = random.randint(0, options.n_model-1)
    value = line.strip()
    for i in range(1, options.n_model+1):
        m = random.random()
        if m < r:
            print "%d\t%s" % (i, value)

还有我的 reducer.py

#!/usr/bin/env python
import sys
import pickle
from optparse import OptionParser
from lrsgd import LogisticRegressionSGD
from utils import parse_svm_light_line

parser = OptionParser()
parser.add_option("-e", "--eta", action="store", dest="eta",
                  default=0.01, help="step size", type="float")
parser.add_option("-c", "--Regularization-Constant", action="store", dest="C",
                  default=0.0, help="regularization strength", type="float")
parser.add_option("-f", "--feature-num", action="store", dest="n_feature",
                  help="number of features", type="int")
options, args = parser.parse_args(sys.argv)

classifier = LogisticRegressionSGD(options.eta, options.C, options.n_feature)

for line in sys.stdin:
    key, value = line.split("\t", 1)
    value = value.strip()
    X, y = parse_svm_light_line(value)
    classifier.fit(X, y)

pickle.dump(classifier, sys.stdout)

当我在代码之外运行它时,它运行正常,但是当我在 hadoop-streaming 中运行它时,它给了我错误:

17/02/07 07:44:34 INFO mapreduce.Job: Task Id : attempt_1486438814591_0038_m_000001_2, Status : FAILED
Error: java.lang.RuntimeException: PipeMapRed.waitOutputThreads(): subprocess failed with code 2
    at org.apache.hadoop.streaming.PipeMapRed.waitOutputThreads(PipeMapRed.java:322)
    at org.apache.hadoop.streaming.PipeMapRed.mapRedFinished(PipeMapRed.java:535)
    at org.apache.hadoop.streaming.PipeMapper.close(PipeMapper.java:130)

【问题讨论】:

  • 这是一个伪分布式设置吗?如果没有,您是否在所有节点上都安装了模块lrsgd?同时发布您用于提交作业的命令。
  • @fanklinsijo 我更新了帖子,向您展示我是如何提交这个的..
  • @franklinsijo,我在哪里检查我正在运行的这个测试集群的数据节点数
  • hdfs dfsadmin -report 应该为您提供实时数据节点的详细信息。
  • @franlinsijo ...我只有 1 个数据节点并且它还活着.. 在报告中.. 所以我很困惑 python 问题在哪里运行.. 添加我有 lrsgd.py 和mapper.py 和 reducer.py 都已经(775)了

标签: python-2.7 hadoop


【解决方案1】:

使用 Harishanker 在帖子中的答案 - How to resolve java.lang.RuntimeException: PipeMapRed.waitOutputThreads(): subprocess failed with code 2?

确保 mapper 和 reducer 文件都可以使用 chmod 执行。 (例如:'chmod 744 mapper.py')

然后制作流式命令:

hadoop jar /usr/lib/hadoop-mapreduce/hadoop-streaming.jar \
-D mapreduce.job.reduces=5  \
-files lr \
-mapper lr/mapper.py -n 5 -r 0.4  \
-reducer lr/reducer.py -f 3618  \
-input training \
-output models 

现在应该可以了。如果没有请评论。

【讨论】:

    猜你喜欢
    • 2013-04-30
    • 1970-01-01
    • 1970-01-01
    • 2022-10-25
    • 1970-01-01
    • 2018-01-28
    • 1970-01-01
    • 2020-06-09
    • 1970-01-01
    相关资源
    最近更新 更多