python - Gunicorn throws OSError opening file when invoked by supervisord -


i have application presents form , generates pdf file pdflatex returned browser file attachment. works when invoke application server manually, when server process started supervisord, breaks...

django throws oserror:

[errno 2] no such file or directory request method: post request url:    http://apps.xxxxxxxx.com/pdf/view/1/85/ django version: 1.4.5 exception type: oserror exception value:     [errno 2] no such file or directory exception location: /usr/lib/python2.7/subprocess.py in _execute_child, line 1249 python executable:  /home/ubuntu/envs/venv/bin/python python version: 2.7.3 

the error thrown line : subprocess.call(shlex.split(proc_string), stdout=open(os.devnull, 'wb'))

the full traceback:

traceback: file "/home/ubuntu/envs/venv/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response   111.                         response = callback(request, *callback_args, **callback_kwargs) file "/home/ubuntu/current/project/appname/apps/catpdf/views.py" in render_preview   114.             subprocess.call(shlex.split(proc_string), stdout=open(os.devnull, 'wb')) file "/usr/lib/python2.7/subprocess.py" in call   493.     return popen(*popenargs, **kwargs).wait() file "/usr/lib/python2.7/subprocess.py" in __init__   679.                             errread, errwrite) file "/usr/lib/python2.7/subprocess.py" in _execute_child   1249.                 raise child_exception  exception type: oserror @ /pdf/view/1/85/ exception value: [errno 2] no such file or directory 

this unusual because when tested application using django dev server, or invoking gunicorn command line gunicorn wsgi:app -- file returned successfully. servers behind nginx.

here's section of code that's throwing error (subprocess.call line):

        output = t.render(cont)         oname = ''.join([slugify(context['qb_full_name']), datetime.datetime.now().strftime("%y%m%d_%h%m")])         out_f = open(''.join([os.path.join(rnddir, oname), '.tex']), "w")         out_f.write(output.encode('utf-8'))         out_f.close()         #jname = ''.join(['-jobname=', oname])         proc_string = ' '.join(['pdflatex', '-output-directory', rnddir, os.path.abspath(out_f.name)])         subprocess.call(shlex.split(proc_string), stdout=open(os.devnull, 'wb'))         fname = os.path.join(rnddir, ''.join([oname, '.pdf']))         pdf = open(fname, 'r')         s in signatures:             os.unlink(s)         response = http.httpresponse(fixedfilewrapper(pdf), content_type=mimetypes.guess_type(fname)[0])         response['content-disposition'] = 'attachment; filename="%s"' % os.path.basename(fname)         response['content-length'] = os.path.getsize(fname)         return response 

local vars django debug:

out_f    <closed file u'/home/ubuntu/current/project/appname/apps/catpdf/rendered/customer-name20130509_1541.tex', mode 'w' @ 0x4211780> signatures   ['/home/ubuntu/current/project/appname/apps/catpdf/tmp/tmpyjruyo.pdf',  '/home/ubuntu/current/project/appname/apps/catpdf/tmp/tmplgmart.pdf'] rnddir '/home/ubuntu/current/project/appname/apps/catpdf/rendered' proc_string  u'pdflatex -output-directory /home/ubuntu/current/project/appname/apps/catpdf/rendered /home/ubuntu/current/project/appname/apps/catpdf/rendered/customer-name20130509_1541.tex' 

supervisor configuration:

[program:gunicorn] directory=%(env_home)s/current/project user=ubuntu command=gunicorn --preload wsgi:appname environment=path="/home/ubuntu/envs/venv/bin" stdout_logfile = %(env_home)s/current/logs/guni-access.log stderr_logfile = %(env_home)s/current/logs/guni-error.log autostart=true autorestart=true priority=997 

you overwriting path environment variable. need use absolute path pdflatex call find it.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -