Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gevent
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gevent
Commits
014c6dfd
Commit
014c6dfd
authored
May 22, 2010
by
Denis Bilenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add examples/geventsendfile.py
parent
5459d682
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
0 deletions
+27
-0
examples/geventsendfile.py
examples/geventsendfile.py
+27
-0
No files found.
examples/geventsendfile.py
0 → 100644
View file @
014c6dfd
"""An example how to use sendfile[1] with gevent.
[1] See http://pypi.python.org/pypi/py-sendfile/
"""
from
errno
import
EAGAIN
from
sendfile
import
sendfile
as
original_sendfile
from
gevent.socket
import
wait_write
def
gevent_sendfile
(
out_fd
,
in_fd
,
offset
,
count
):
total_sent
=
0
while
total_sent
<
count
:
try
:
_offset
,
sent
=
original_sendfile
(
out_fd
,
in_fd
,
offset
+
total_sent
,
count
-
total_sent
)
#print '%s: sent %s [%d%%]' % (out_fd, sent, 100*total_sent/count)
total_sent
+=
sent
except
OSError
,
ex
:
if
ex
[
0
]
==
EAGAIN
:
wait_write
(
out_fd
)
else
:
raise
return
offset
+
total_sent
,
total_sent
def
patch_sendfile
():
import
sendfile
sendfile
.
sendfile
=
gevent_sendfile
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment