Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

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

Closed
deep2code opened this issue Dec 9, 2015 · 8 comments
Closed

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

deep2code opened this issue Dec 9, 2015 · 8 comments

Comments

@deep2code
Copy link

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

@benoitc
Copy link
Owner

benoitc commented Dec 10, 2015

@YiJunJun what is the issue?

@deep2code
Copy link
Author

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
Copy link
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.

@deep2code
Copy link
Author

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
Copy link

pudo commented Dec 16, 2015

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

@volnt
Copy link

volnt commented Dec 18, 2015

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

@tilgovi
Copy link
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
Copy link
Owner

benoitc commented Dec 28, 2015

@tilgovi sounds like a plan :)

mjjbell pushed a commit to mjjbell/gunicorn that referenced this issue Mar 16, 2018
If the filelike response object has no `fileno` attribute, then skip
trying to use sendfile rather than failing with an error.

Close benoitc#1160
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

5 participants