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
61c768b4
Commit
61c768b4
authored
Sep 15, 2010
by
Denis Bilenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
examples: follow pep8
parent
1bb128b8
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
12 additions
and
11 deletions
+12
-11
examples/concurrent_download.py
examples/concurrent_download.py
+1
-1
examples/dns_mass_resolve.py
examples/dns_mass_resolve.py
+1
-2
examples/httpserver.py
examples/httpserver.py
+1
-0
examples/processes.py
examples/processes.py
+4
-3
examples/webpy.py
examples/webpy.py
+3
-3
examples/wsgiserver.py
examples/wsgiserver.py
+1
-1
examples/wsgiserver_ssl.py
examples/wsgiserver_ssl.py
+1
-1
No files found.
examples/concurrent_download.py
View file @
61c768b4
...
@@ -13,6 +13,7 @@ monkey.patch_all()
...
@@ -13,6 +13,7 @@ monkey.patch_all()
import
urllib2
import
urllib2
def
print_head
(
url
):
def
print_head
(
url
):
print
'Starting %s'
%
url
print
'Starting %s'
%
url
data
=
urllib2
.
urlopen
(
url
).
read
()
data
=
urllib2
.
urlopen
(
url
).
read
()
...
@@ -21,4 +22,3 @@ def print_head(url):
...
@@ -21,4 +22,3 @@ def print_head(url):
jobs
=
[
gevent
.
spawn
(
print_head
,
url
)
for
url
in
urls
]
jobs
=
[
gevent
.
spawn
(
print_head
,
url
)
for
url
in
urls
]
gevent
.
joinall
(
jobs
)
gevent
.
joinall
(
jobs
)
examples/dns_mass_resolve.py
View file @
61c768b4
...
@@ -12,12 +12,11 @@ from gevent import socket
...
@@ -12,12 +12,11 @@ from gevent import socket
from
gevent.pool
import
Pool
from
gevent.pool
import
Pool
N
=
1000
N
=
1000
# limit ourselves to max 10 simultaneous outstanding requests
# limit ourselves to max 10 simultaneous outstanding requests
pool
=
Pool
(
10
)
pool
=
Pool
(
10
)
finished
=
0
finished
=
0
def
job
(
url
):
def
job
(
url
):
global
finished
global
finished
try
:
try
:
...
...
examples/httpserver.py
View file @
61c768b4
...
@@ -6,6 +6,7 @@ WSGI interface is a safer choice, see examples/wsgiserver.py.
...
@@ -6,6 +6,7 @@ WSGI interface is a safer choice, see examples/wsgiserver.py.
"""
"""
from
gevent
import
http
from
gevent
import
http
def
callback
(
request
):
def
callback
(
request
):
print
request
print
request
if
request
.
uri
==
'/'
:
if
request
.
uri
==
'/'
:
...
...
examples/processes.py
View file @
61c768b4
...
@@ -12,14 +12,15 @@ from gevent import socket
...
@@ -12,14 +12,15 @@ from gevent import socket
import
subprocess
import
subprocess
import
errno
import
errno
import
sys
import
sys
import
fcntl
,
os
import
os
import
fcntl
def
popen_communicate
(
args
,
data
=
''
):
def
popen_communicate
(
args
,
data
=
''
):
"""Communicate with the process non-blockingly."""
"""Communicate with the process non-blockingly."""
p
=
subprocess
.
Popen
(
args
,
stdin
=
subprocess
.
PIPE
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
STDOUT
)
p
=
subprocess
.
Popen
(
args
,
stdin
=
subprocess
.
PIPE
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
STDOUT
)
fcntl
.
fcntl
(
p
.
stdin
,
fcntl
.
F_SETFL
,
os
.
O_NONBLOCK
)
# make the file nonblocking
fcntl
.
fcntl
(
p
.
stdin
,
fcntl
.
F_SETFL
,
os
.
O_NONBLOCK
)
# make the file nonblocking
fcntl
.
fcntl
(
p
.
stdout
,
fcntl
.
F_SETFL
,
os
.
O_NONBLOCK
)
# make the file nonblocking
fcntl
.
fcntl
(
p
.
stdout
,
fcntl
.
F_SETFL
,
os
.
O_NONBLOCK
)
# make the file nonblocking
bytes_total
=
len
(
data
)
bytes_total
=
len
(
data
)
bytes_written
=
0
bytes_written
=
0
...
...
examples/webpy.py
View file @
61c768b4
#!/usr/bin/python
#!/usr/bin/python
"""A web.py application powered by gevent"""
"""A web.py application powered by gevent"""
from
gevent
import
monkey
;
monkey
.
patch_all
()
from
gevent
import
monkey
;
monkey
.
patch_all
()
...
@@ -10,10 +9,12 @@ import web
...
@@ -10,10 +9,12 @@ import web
urls
=
(
"/"
,
"index"
,
urls
=
(
"/"
,
"index"
,
'/long'
,
'long_polling'
)
'/long'
,
'long_polling'
)
class
index
:
class
index
:
def
GET
(
self
):
def
GET
(
self
):
return
'Hello, world!<br><a href="/long">/long</a>'
return
'Hello, world!<br><a href="/long">/long</a>'
class
long_polling
:
class
long_polling
:
# Since gevent.wsgi executes each incoming connection in a separate greenlet
# Since gevent.wsgi executes each incoming connection in a separate greenlet
# long running requests such as this one don't block one another;
# long running requests such as this one don't block one another;
...
@@ -21,11 +22,10 @@ class long_polling:
...
@@ -21,11 +22,10 @@ class long_polling:
# becomes greenlet-local storage thus making requests isolated as they should be.
# becomes greenlet-local storage thus making requests isolated as they should be.
def
GET
(
self
):
def
GET
(
self
):
print
'handling GET context id = %s'
%
(
id
(
web
.
ctx
.
_getd
()),
)
print
'handling GET context id = %s'
%
(
id
(
web
.
ctx
.
_getd
()),
)
gevent
.
sleep
(
10
)
# possible to block the request indefinitely, without harming others
gevent
.
sleep
(
10
)
# possible to block the request indefinitely, without harming others
return
'Hello, 10 seconds later'
return
'Hello, 10 seconds later'
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
application
=
web
.
application
(
urls
,
globals
()).
wsgifunc
()
application
=
web
.
application
(
urls
,
globals
()).
wsgifunc
()
print
'Serving on 8088...'
print
'Serving on 8088...'
WSGIServer
((
''
,
8088
),
application
).
serve_forever
()
WSGIServer
((
''
,
8088
),
application
).
serve_forever
()
examples/wsgiserver.py
View file @
61c768b4
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
from
gevent
import
wsgi
from
gevent
import
wsgi
def
hello_world
(
env
,
start_response
):
def
hello_world
(
env
,
start_response
):
if
env
[
'PATH_INFO'
]
==
'/'
:
if
env
[
'PATH_INFO'
]
==
'/'
:
start_response
(
'200 OK'
,
[(
'Content-Type'
,
'text/html'
)])
start_response
(
'200 OK'
,
[(
'Content-Type'
,
'text/html'
)])
...
@@ -13,4 +14,3 @@ def hello_world(env, start_response):
...
@@ -13,4 +14,3 @@ def hello_world(env, start_response):
print
'Serving on 8088...'
print
'Serving on 8088...'
wsgi
.
WSGIServer
((
''
,
8088
),
hello_world
).
serve_forever
()
wsgi
.
WSGIServer
((
''
,
8088
),
hello_world
).
serve_forever
()
examples/wsgiserver_ssl.py
View file @
61c768b4
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
from
gevent
import
pywsgi
from
gevent
import
pywsgi
def
hello_world
(
env
,
start_response
):
def
hello_world
(
env
,
start_response
):
if
env
[
'PATH_INFO'
]
==
'/'
:
if
env
[
'PATH_INFO'
]
==
'/'
:
start_response
(
'200 OK'
,
[(
'Content-Type'
,
'text/html'
)])
start_response
(
'200 OK'
,
[(
'Content-Type'
,
'text/html'
)])
...
@@ -16,4 +17,3 @@ server = pywsgi.WSGIServer(('0.0.0.0', 8443), hello_world, keyfile='server.key',
...
@@ -16,4 +17,3 @@ server = pywsgi.WSGIServer(('0.0.0.0', 8443), hello_world, keyfile='server.key',
# to start the server asynchronously, call server.start()
# to start the server asynchronously, call server.start()
# we use blocking serve_forever() here because we have no other jobs
# we use blocking serve_forever() here because we have no other jobs
server
.
serve_forever
()
server
.
serve_forever
()
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