gunicorn+gevent/eventlet+flask+send_file, cStringIO? #1160

Closed
yijunjun opened this Issue Dec 9, 2015 · 8 comments

Projects

None yet

5 participants

@yijunjun
yijunjun commented Dec 9, 2015

in flask:
@app.route("/test")
def test():
import cStringIO
output = cStringIO.StringIO()
...
return send_file(output)

@benoitc
Owner
benoitc commented Dec 10, 2015

@yijunjun what is the issue?

@yijunjun

Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/gunicorn/workers/sync.py", line 130, in handle
self.handle_request(listener, req, client, addr)
File "/usr/lib/python2.7/site-packages/gunicorn/workers/sync.py", line 174, in handle_request
resp.write_file(respiter)
File "/usr/lib/python2.7/site-packages/gunicorn/http/wsgi.py", line 394, in write_file
if not self.sendfile(respiter):
File "/usr/lib/python2.7/site-packages/gunicorn/http/wsgi.py", line 357, in sendfile
fileno = respiter.filelike.fileno()
AttributeError: 'cStringIO.StringO' object has no attribute 'fileno'

@benoitc
Owner
benoitc commented Dec 11, 2015

@tilgovi ping

The issue comes from the removal of the fileobject testing:
18d2b92#diff-0b90f794c3e9742c45bf484505e3db8dL520

I am really not sure we shouldn't be strict there and only accept fileobjects providing a fileno method or attribute

@yijunjun in the mean time why do you want to use sendfile here? Why not simply returning an iterator (the StringIO would be enough). Gunicorn will stream it.

@yijunjun

I can solve this problem.I just want to report a problem.Thank you for your answer.

@tilgovi tilgovi self-assigned this Dec 11, 2015
@pudo
pudo commented Dec 16, 2015

Got the same issue. Wonder if it can't be caught more softly.

@volnt
volnt commented Dec 18, 2015

Got the same problem here too. How can this be avoided ?

@tilgovi
Collaborator
tilgovi commented Dec 18, 2015

We can catch the exception. I should be able to get to this over the weekend if no one else can. Closing any other issues on the milestone will help get this released faster.

@benoitc
Owner
benoitc commented Dec 28, 2015

@tilgovi sounds like a plan :)

@tilgovi tilgovi added a commit that closed this issue Dec 28, 2015
@tilgovi tilgovi Catch sendfile failure from no file descriptor
If the filelike response object has no `fileno` attribute, then skip
trying to use sendfile rather than failing with an error.

Close #1160
98c9e3b
@tilgovi tilgovi closed this in 98c9e3b Dec 28, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment