Skip to content

Commit 2e79d13

Browse files
committed
Add urlopen_mc.mochi as an example of use spawn_mc. The execution speed is slower than urlopen.mochi because it is the I/O-bound task.
1 parent 0172352 commit 2e79d13

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

examples/urlopen_m.mochi

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#from eventlet.green.urllib.request import urlopen
2+
#import json
3+
4+
urls = [
5+
"http://weather.livedoor.com/forecast/webservice/json/v1?city=140010",
6+
"http://weather.livedoor.com/forecast/webservice/json/v1?city=130010",
7+
"http://weather.livedoor.com/forecast/webservice/json/v1?city=400040"
8+
] * 10
9+
10+
11+
def read(url):
12+
from eventlet.green.urllib.request import urlopen
13+
import json
14+
15+
weather = urlopen(url).read().decode('utf-8') |> json.loads()
16+
print(weather['title'])
17+
map(-> print($1['dateLabel'], $1['telop']),
18+
weather['forecasts']) |> doall()
19+
print('')
20+
21+
22+
def fetch():
23+
from eventlet.green.urllib.request import urlopen
24+
import json
25+
26+
receive:
27+
url: read(url)
28+
29+
urls !&> spawn_mc(fetch)
30+
wait_all()

0 commit comments

Comments
 (0)