Last active
December 10, 2017 11:19
-
-
Save antimon2/6944d60c126939b6704aa594466770be to your computer and use it in GitHub Desktop.
ChannelSamples.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"metadata": { | |
"ExecuteTime": { | |
"start_time": "2017-12-10T11:17:14.880Z", | |
"end_time": "2017-12-10T20:17:19.711000+09:00" | |
}, | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "# Pkg.add(\"Requests\")\nusing Requests", | |
"execution_count": 1, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"ExecuteTime": { | |
"start_time": "2017-12-10T11:17:20.724Z", | |
"end_time": "2017-12-10T20:17:21.220000+09:00" | |
}, | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "function do_search(results::Channel{Tuple{String, Float64, HttpCommon.Response}}, engine::String, url::String)\n res, exec_time = @timed get(url)\n if isopen(results)\n put!(results, (engine, exec_time, res))\n end\nend", | |
"execution_count": 2, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 2, | |
"data": { | |
"text/plain": "do_search (generic function with 1 method)" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"ExecuteTime": { | |
"start_time": "2017-12-10T11:17:22.028Z", | |
"end_time": "2017-12-10T20:17:22.035000+09:00" | |
}, | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "function main()\n results = Channel{Tuple{String, Float64, HttpCommon.Response}}(3)\n \n searches = [\n \"Yahoo\"=>\"https://search.yahoo.co.jp/search?p=julialang\", \n \"Google\"=>\"https://www.google.co.jp/search?q=julialang\", \n \"Bing\"=>\"https://www.bing.com/search?q=julialang\"]\n for (engine, url) = searches\n @schedule do_search(results, engine, url)\n end\n\n res0 = take!(results)\n close(results)\n \n println(res0...)\nend", | |
"execution_count": 3, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 3, | |
"data": { | |
"text/plain": "main (generic function with 1 method)" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"ExecuteTime": { | |
"start_time": "2017-12-10T11:17:24.064Z", | |
"end_time": "2017-12-10T20:17:26.430000+09:00" | |
}, | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "main()", | |
"execution_count": 4, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": "Google0.921427654Response(200 OK, 16 headers, 52069 bytes in body)\n", | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"ExecuteTime": { | |
"start_time": "2017-12-10T11:17:32.246Z", | |
"end_time": "2017-12-10T20:17:32.891000+09:00" | |
}, | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "main()", | |
"execution_count": 5, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": "Bing0.770564858Response(200 OK, 13 headers, 90888 bytes in body)\n", | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"ExecuteTime": { | |
"start_time": "2017-12-10T11:17:32.246Z", | |
"end_time": "2017-12-10T20:17:32.891000+09:00" | |
}, | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "main()", | |
"execution_count": 6, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": "Bing0.648154419Response(200 OK, 13 headers, 89350 bytes in body)\n", | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"ExecuteTime": { | |
"start_time": "2017-12-10T11:17:32.246Z", | |
"end_time": "2017-12-10T20:17:32.891000+09:00" | |
}, | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "main()", | |
"execution_count": 7, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": "Google0.764888553Response(200 OK, 16 headers, 52006 bytes in body)\n", | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"ExecuteTime": { | |
"start_time": "2017-12-10T11:17:32.246Z", | |
"end_time": "2017-12-10T20:17:32.891000+09:00" | |
}, | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "main()", | |
"execution_count": 8, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": "Google0.642048228Response(200 OK, 16 headers, 51923 bytes in body)\n", | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"ExecuteTime": { | |
"start_time": "2017-12-10T11:18:05.131Z", | |
"end_time": "2017-12-10T20:18:05.138000+09:00" | |
}, | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "function main2()\n results = Channel{Tuple{String, Float64, HttpCommon.Response}}(3)\n \n searches = [\n \"Yahoo\"=>\"https://search.yahoo.co.jp/search?p=julialang\", \n \"Google\"=>\"https://www.google.co.jp/search?q=julialang\", \n \"Bing\"=>\"https://www.bing.com/search?q=julialang\"]\n for (engine, url) = searches\n @schedule do_search(results, engine, url)\n end\n\n res1 = take!(results)\n println(res1...)\n \n res2 = take!(results)\n println(res2...)\n \n res3 = take!(results)\n println(res3...)\n \n close(results)\nend", | |
"execution_count": 9, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 9, | |
"data": { | |
"text/plain": "main2 (generic function with 1 method)" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"ExecuteTime": { | |
"start_time": "2017-12-10T11:18:07.627Z", | |
"end_time": "2017-12-10T20:18:08.899000+09:00" | |
}, | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "main2()", | |
"execution_count": 10, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": "Google0.685931991Response(200 OK, 16 headers, 52070 bytes in body)\nBing0.691108047Response(200 OK, 13 headers, 91184 bytes in body)\nYahoo1.240782096Response(200 OK, 14 headers, 10487 bytes in body)\n", | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "", | |
"execution_count": null, | |
"outputs": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"name": "julia-0.6", | |
"display_name": "Julia 0.6.1", | |
"language": "julia" | |
}, | |
"language_info": { | |
"file_extension": ".jl", | |
"name": "julia", | |
"mimetype": "application/julia", | |
"version": "0.6.1" | |
}, | |
"gist": { | |
"id": "", | |
"data": { | |
"description": "ChannelSamples.ipynb", | |
"public": true | |
} | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment