我正在为我的其余 api 使用 python bottle 服务器。收到请求后,我正在使用 os.system 调用 RScript。 rscript 需要一些时间才能执行,之后它会继续操作。我的问题是当多个用户使用 api 时,它会排队并且不会并行发生。
@route('/UploadFiles', method='POST')
def UploadFiles():
#Reading the initial text file to get application name and other details
with open('/home/user/abc.txt') as f:
for line in f:
if('Application Name' in line):
appName=line.split(" - ")
appName=str(appName[1])
appName=appName.strip()
print "inside upload files"
uniquename=str(uuid.uuid1())
print "uuid is :",uniquename
retcode = subprocess.call(['Rscript','/home/user/RProgram.r',uniquename])
print "executed r script"
run(host='192.168.1.155', port=8555)
所有这些都必须对每个用户并行发生。但它正在排队。我在这里做错了什么。
我正在运行
sudo nohup python restcall.py -&
所以打印语句不是我认为的问题。
请您参考如下方法:
我想我找到了解决办法。它现在对我有用。Bottle 默认在内置的 wsgiref WSGIServer 上运行。这种非线程 HTTP 服务器非常适合开发和早期生产,但当服务器负载增加时可能会成为性能瓶颈。
提高性能的最简单方法是安装多线程服务器库,如 paste 或 cherrypy,并告诉 Bottle 使用它而不是单线程服务器:
bottle.run(server='paste')
