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
f95e14d3
Commit
f95e14d3
authored
Dec 01, 2009
by
Denis Bilenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
simplify example concurrent_download.py
- do not use Pool as it's already demoed in dns_mass_resolve.py
parent
e0078c70
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
3 additions
and
9 deletions
+3
-9
examples/concurrent_download.py
examples/concurrent_download.py
+3
-9
No files found.
examples/concurrent_download.py
View file @
f95e14d3
...
...
@@ -4,24 +4,18 @@
urls
=
[
'http://www.google.com'
,
'http://www.yandex.ru'
,
'http://www.python.org'
]
import
gevent
from
gevent
import
monkey
monkey
.
patch_socket
()
# patches regular socket to yield to other greenlets
import
urllib2
from
gevent.pool
import
Pool
# Pool accepts one optional argument - maximum number of concurrent
# coroutines that can be active at any given moment.
# Try passing 1 or 2 here to see the effect.
pool
=
Pool
()
def
print_head
(
url
):
print
'Starting %s'
%
url
data
=
urllib2
.
urlopen
(
url
).
read
()
print
'%s: %s bytes: %r'
%
(
url
,
len
(
data
),
data
[:
50
])
for
url
in
urls
:
pool
.
spawn
(
print_head
,
url
)
jobs
=
[
gevent
.
spawn
(
print_head
,
url
)
for
url
in
urls
]
pool
.
join
(
)
gevent
.
joinall
(
jobs
)
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