Wednesday, 15 January 2014

Asynchronous callback functions in python -



Asynchronous callback functions in python -

i trying implement rest api in python using flask. however, api implementation in turn needs create network calls (db example). improve throughput can create asynchronous? mean this. lets suppose teh rest api foo()

def foo(): # 1. stuff needed # 2. phone call make_network_call , wait return. # 3. stuff needed returned data. # 4. return.

now if know going take time @ step 2, can give cpu here , process other incoming requests , come when returns? if how do , frameworks involved? using python flask currently.

flask can run multiple threads or processes when it's launched, see this question. wont create foo() more efficient, able serve multiple clients simultaneously.

to run multiple threads or processes, can specify in flask.run() keywords:

for threads:

if __name__ == '__main__': app.run(threaded=true)

or processes:

if __name__ == '__main__': app.run(processes=5) # or many you may want.

python asynchronous

No comments:

Post a Comment