uwsgi 部署的django 如何平稳运行 subprocess ?

我使用uwsgi部署django,在django程序中使用subprocess调用系统安装的pdf2htmlEX。
当使用django自带的manage.py runserver时,服务正常运行。
但使用uwsgi部署后,subprocess 的 returncode 为 -11,据查是段错误的意思。
但同样的环境,同样的参数与文件,runserver调用状态正常,单独跑python程序调用也正常,但使用uwsgi部署后调用就不正常,这是怎么回事?
(查了有说在uwsgi设置里加 close-on-exec,但加了也不好使。。。。)
代码如下形式。

from subprocess import call
def pdf2html(pdfpath,outputpath,filename):
    '''将pdf转为html,字体文件与html文件同级'''
    if not os.path.exists(outputpath + '/' + filename):
        os.mkdir(outputpath + '/' + filename)
    shellstr = ['pdf2htmlEX', '--dest-dir', outputpath + '/' + filename, '--embed-font', '0','--embed-image', '0','--embed-external-font', '0','--embed-css', '0', '--no-drm', '1', pdfpath + '/' + filename + '.pdf']
    print(shellstr)
    shellresult = call(shellstr,shell=False,close_fds=True)
    return shellresult

def 接口(request):
    #......
    returncode = pdf2html(...) #用uwsgi部署后,同样的参数在这就返回 -11 。

我的uwsgi配置:

# backend_uwsgi.ini file
[uwsgi]

# Django-related settings
# the base directory (full path)
chdir           = /home/serverend/comengine

# Django's wsgi file
module          = comengine.wsgi

 
# process-related settings
# master
master          = true
# maximum number of worker processes
processes       = 8
threads         = 4

post-buffering = 65536

buffer-size = 65536

# the socket (use the full path to be safe),将socket写入sock文件,安全又便捷
socket          = /home/serverend/comengine/comengine/comengine.sock

# ... with appropriate permissions - may be needed
chmod-socket    = 666

# clear environment on exit
vacuum          = true

uwsgi_read_timeout = 60000
uwsgi_send_timeout = 60000

#不记录access log
disable-logging = true

#设置每个工作进程的最大请求数,超过该请求数,该工作进程就会回收重启
max-requests = 1000

#当某个工作进程占用内存超过1000M时,该工作进程回收重启
reload-on-as = 50000
reload-on-rss = 8500

#据说加上这个锁比较安全
thunder-lock

# 设置在平滑的重启(直到接收到的请求处理完才重启)一个工作子进程中,等待这个工作结束的最长秒数。这个配置会使在平滑地重启工作子进程中,如果工作进程结束时间超过了72000秒就会被强行结束(忽略之前已经接收到的请求而直接结束)
worker-reload-mercy = 72000

#ignore-sigpipe  = true
#ignore-write-errors = true
#disable-write-exception = true

close-on-exec = true

touch-logreopen = /home/serverend/nginxsetting/log/.touchforlogrotate
daemonize = /home/serverend/nginxsetting/log/uwsgi.log
阅读 4.5k
3 个回答

已经解决了。

新手上路,请多包涵

你好,请问你的 uwsgi 部署的django 如何平稳运行 subprocess ? 这个问题是怎么解决的?我也碰到这个问题了,请教一下

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题