簡體   English   中英

使用Python中的restful service啟動Spark-Submit

[英]Launch Spark-Submit with restful service in Python

按照教程,我在python中做了一個安靜的服務。 使用這個服務我想用spark-submit調用另一個python腳本,但它不起作用。

這是我的service.py

import pickle
import subprocess
from flask import Flask, request
from flask_restful import Resource, Api
from json import dumps
from flask_jsonpify import jsonify

app = Flask(__name__)
api = Api(app)

class Test(Resource):
    def post(self):
        imageID = request.form.get('imageID')
        tags = request.form.get('tags')

        return subprocess.call("spark-submit NaiveBayesClassifier.py",shell=True,stderr=subprocess.STDOUT)


api.add_resource(Test, '/test') 

if __name__ == '__main__':
    app.run(port=5002)

這個服務是使用virtualenv開始使用這個:

source venv/bin/activate
python service.py

但是當腳本運行ubprocess.call("spark-submit NaiveBayesClassifier.py",shell=True,stderr=subprocess.STDOUT)它會返回此錯誤:

Running on http://127.0.0.1:5002/ (Press CTRL+C to quit)
OpenJDK 64-Bit Server VM warning: Insufficient space for shared memory 
file:
   34475
 Try using the -Djava.io.tmpdir= option to select an alternate temp location.

 OpenJDK 64-Bit Server VM warning: Insufficient space for shared memory file:
   34462
Try using the -Djava.io.tmpdir= option to select an alternate temp location.

Traceback (most recent call last):
  File "/home/usertest/project/NaiveBayesClassifier.py", line 2, in <module>
    import numpy
ImportError: No module named numpy
127.0.0.1 - - [23/Feb/2018 14:36:06] "POST /test HTTP/1.1" 200 -

關於這個問題的任何想法? 我正在使用Spark 1.6.1

我看到三個問題。

首先在你的代碼中,你應該以這種方式使用Popen:

class Test(Resource):
    def post(self):
        imageID = request.form.get('imageID')
        tags = request.form.get('tags')

        p = subprocess.Popen(["spark-submit", "NaiveBayesClassifier.py"], stdout=subprocess.PIPE)
        return p.communicate()

你的virtualenv中應該安裝第二個 pip

pip install numpy

如果出現錯誤,請使用sudo

sudo pip install numpy

第三,此消息表示硬盤中沒有更多空間。 如果可以的話,嘗試刪除一些大文件或者刪除你的分區。

warning: Insufficient space for shared memory file: 34475

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM