On Saturday, March 5, 2016 at 4:08:58 PM UTC-8, Francisco Betancourt wrote:
>
> Hi. I have an app that has been in production for about two years. Today I
> moved the application and everything went well except for a small function
> that uses subprocess call with phantomjs to generate a pdf file, it used to
> work fine, but now I get a Internal Server Error.
>
The short answer is that you are experiencing a timeout on a step that
requires longer than typical page results do. The easy way to fix this is
to move the PDF generation out of the request by queuing a scheduler task.
You may want your page to use ajax calls to load the results; you can use
periodic ajax calls (every 5 seconds, say) to poll for the generation being
complete, Or you may want to have the user go off and do something else,
and maybe email the PDF to the user. This depends on your workflow.
> The controller looks like this:
>
> def recibo_pdf():
> uuid=request.vars.uuid
>
> jsf=request.env.web2py_path+'/applications/'+request.application+'/static/js/rasterize.js'
>
> url=URL('honorarios','recibo_honorarios',vars={'uuid':uuid},scheme='https',host=True)
>
> out=request.env.web2py_path+'/applications/'+request.application+'/static/pdfs/'+uuid+'.pdf'
> from subprocess import call
> ret=call(['phantomjs',jsf,url,out,'Letter'])
> pdf=open(out,'r')
> response.headers['Content-Type']='application/pdf'
> response.headers['Content-Disposition']='attachment;
> filename='+request.vars.uuid+'.pdf'
> response.headers['Content-Title']=request.vars.uuid+'.pdf'
> return pdf.read()
>
> If I run from the server:
>
> python web2py.py -S init/controller -M
>
> request.vars.uuid=some_uuid
> recibo_pdf()
>
> It works fine, but when I run it from the browser it takes a lot of time
> and eventually generates an Internal Error pdf. Does any body has any ideas
> how to debug this? I have search in the apache error logs and all it has is
> this:
>
> [Sat Mar 05 17:53:31.771873 2016] [core:error] [pid 937:tid 2944346944]
> [client 127.0.0.1:34929] Script timed out before returning headers:
> wsgihandler.py
>
>
This is the clue.
>
> [update]
>
> I was able to get it working adding this to my apache configuration file:
>
> WSGIApplicationGroup %{GLOBAL}
>
> Can any one help me explain why?
>
>
>
>
You may be extending the timeout on the WSGI call, but that could make some
other part of the user experience less pleasant.
/dps
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.