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

yijunjun opened this Issue Dec 9, 2015 · 8 comments


None yet

5 participants

yijunjun commented Dec 9, 2015

in flask:
def test():
import cStringIO
output = cStringIO.StringIO()
return send_file(output)

benoitc commented Dec 10, 2015

@yijunjun what is the issue?


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

benoitc commented Dec 11, 2015

@tilgovi ping

The issue comes from the removal of the fileobject testing:

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.


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 commented Dec 16, 2015

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

volnt commented Dec 18, 2015

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

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 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
@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