python 2.7 - Multiprocessing Pool in python2 not working -


i trying put call 3 other apis in form of multiprocessing api hosted on 8080. here code using (python 3.4):

import requests, json flask import flask, request concurrent import futures  def getrequest(*args):     return requests.get(args[0],params = args[1])  process = futures.processpoolexecutor(3) some_text =  open('lines.txt').read() # text params = {'text': some_text} url1 = 'http://localhost:8081' # api2 url2 = 'http://localhost:8082' # api1 url3 = 'http://localhost:8083' # api3 g = process.map(getrequest, [[url1,params], [url2,params], [url3, params]]) 

above code snippet sits in flask app running on port 8080. can connect port 8080 , requests being sent ports 8081,8082, 8083 in parallel there have been data type mismatch between these apis. automatically changes json.dumps(arg[0],arg[1])'s data form.

all other apis work fine individually.

this error getting:

127.0.0.1 - - [16/jul/2015 21:58:18] "get /?%7b%22article%22:%20%22american%20profile%20-%20american%20profile%20celebrates%20the%20intriguing%20people,%20places%20and%20things%20in%20hometowns%20across%20the%20country%20along%20with%20features%20on%20music,%20film,%20tv,%20seasonal%20recipes,%20health%20and%20family%20finance.%20get%20every%20new%20post%20delivered%20to%20your%20inbox.%20join%20184%20other%20followers%20%5cn%22%7d http/1.1" 500 - traceback (most recent call last):   file "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1836, in __call__     return self.wsgi_app(environ, start_response)   file "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1820, in wsgi_app     response = self.make_response(self.handle_exception(e))   file "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1403, in handle_exception     reraise(exc_type, exc_value, tb)   file "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app     response = self.full_dispatch_request()   file "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request     rv = self.handle_user_exception(e)   file "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1381, in handle_user_exception     reraise(exc_type, exc_value, tb)   file "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request     rv = self.dispatch_request()   file "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1461, in dispatch_request     return self.view_functions[rule.endpoint](**req.view_args)   file "/users/prateekgupta/desktop/project-annie/phrase_extraction/code/getnounsandnounphrases.py", line 18, in getkeywords     vals = eval(request.data) file "<string>", line 0      ^ syntaxerror: unexpected eof while parsing 

this api on port 8081 (python 2.7):

# api app=flask(__name__) @app.route('/', methods=['get', 'post']) def getsomething():     vals = dict(request.args)['key'][0] # hack. idk when use args. ideally pass json , json     return json.dumps(some_function(vals), indent=4) + '\n'   # start app here if __name__ == '__main__':     app.debug = true     app.run(host='0.0.0.0', port =8081) 

i have tried different configurations arguments of no use.

eval not opposite of json.dumps, json.loads (eval treats payload python code , json not proper subset of python).

change getsomething handler use vals = json.loads(request.data) (or better, vals = request.get_json(force=true)) , things should work expected.


Comments