使用os.system命令处理python瓶中的多用户方案

时间:2015-11-09 06:44:49

标签: python bottle os.system

我正在使用python bottle服务器为我的其他api.On获取请求我使用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 -& 

所以打印报表不是我认为的问题。

1 个答案:

答案 0 :(得分:1)

我想我找到了解决方案。它现在正在为我工​​作.Bottle默认运行在内置的wsgiref WSGIServer上。这种非线程HTTP服务器非常适合开发和早期生产,但在服务器负载增加时可能会成为性能瓶颈。

提高性能的最简单方法是安装多线程服务器库,如paste或cherrypy,并告诉Bottle使用它而不是单线程服务器:

bottle.run(server='paste')

Referencing python bottle documentation