gpt4 book ai didi

python - 使用 os.system 命令处理 python bottle 中的多用户场景

转载 作者:太空宇宙 更新时间:2023-11-04 05:42:01 25 4
gpt4 key购买 nike

我正在为我的其余 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')

Referencing python bottle documentation

关于python - 使用 os.system 命令处理 python bottle 中的多用户场景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33603764/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com