Created
August 20, 2020 04:47
-
-
Save im-noob/0da38380c16ca3d6e3b1840d5f79b19c to your computer and use it in GitHub Desktop.
MiliionRequest.ipynb
This file contains hidden or 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
{ | |
"nbformat": 4, | |
"nbformat_minor": 0, | |
"metadata": { | |
"colab": { | |
"name": "MiliionRequest.ipynb", | |
"provenance": [], | |
"collapsed_sections": [], | |
"authorship_tag": "ABX9TyMLkZCHs1ngHiXLWhdKzTqW", | |
"include_colab_link": true | |
}, | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3" | |
} | |
}, | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "view-in-github", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"<a href=\"https://colab.research.google.com/gist/im-noob/0da38380c16ca3d6e3b1840d5f79b19c/miliionrequest.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "xMDzwd34HXqC", | |
"colab_type": "code", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 513 | |
}, | |
"outputId": "80695adb-57a7-40ce-fcce-b586cb82b26b" | |
}, | |
"source": [ | |
"!pip install nest_asyncio\n", | |
"!pip install aiohttp" | |
], | |
"execution_count": 5, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"Collecting nest_asyncio\n", | |
" Downloading https://files.pythonhosted.org/packages/a0/44/f2983c5be9803b08f89380229997e92c4bdd7a4a510ccee565b599d1bdc8/nest_asyncio-1.4.0-py3-none-any.whl\n", | |
"Installing collected packages: nest-asyncio\n", | |
"Successfully installed nest-asyncio-1.4.0\n", | |
"Collecting aiohttp\n", | |
"\u001b[?25l Downloading https://files.pythonhosted.org/packages/7c/39/7eb5f98d24904e0f6d3edb505d4aa60e3ef83c0a58d6fe18244a51757247/aiohttp-3.6.2-cp36-cp36m-manylinux1_x86_64.whl (1.2MB)\n", | |
"\u001b[K |████████████████████████████████| 1.2MB 5.0MB/s \n", | |
"\u001b[?25hRequirement already satisfied: chardet<4.0,>=2.0 in /usr/local/lib/python3.6/dist-packages (from aiohttp) (3.0.4)\n", | |
"Requirement already satisfied: typing-extensions>=3.6.5; python_version < \"3.7\" in /usr/local/lib/python3.6/dist-packages (from aiohttp) (3.7.4.2)\n", | |
"Collecting multidict<5.0,>=4.5\n", | |
"\u001b[?25l Downloading https://files.pythonhosted.org/packages/1a/95/f50352b5366e7d579e8b99631680a9e32e1b22adfa1629a8f23b1d22d5e2/multidict-4.7.6-cp36-cp36m-manylinux1_x86_64.whl (148kB)\n", | |
"\u001b[K |████████████████████████████████| 153kB 32.2MB/s \n", | |
"\u001b[?25hCollecting idna-ssl>=1.0; python_version < \"3.7\"\n", | |
" Downloading https://files.pythonhosted.org/packages/46/03/07c4894aae38b0de52b52586b24bf189bb83e4ddabfe2e2c8f2419eec6f4/idna-ssl-1.1.0.tar.gz\n", | |
"Collecting yarl<2.0,>=1.0\n", | |
"\u001b[?25l Downloading https://files.pythonhosted.org/packages/a0/b4/2cbeaf2c3ea53865d9613b315fe24e78c66acedb1df7e4be4e064c87203b/yarl-1.5.1-cp36-cp36m-manylinux1_x86_64.whl (257kB)\n", | |
"\u001b[K |████████████████████████████████| 266kB 24.0MB/s \n", | |
"\u001b[?25hRequirement already satisfied: attrs>=17.3.0 in /usr/local/lib/python3.6/dist-packages (from aiohttp) (19.3.0)\n", | |
"Collecting async-timeout<4.0,>=3.0\n", | |
" Downloading https://files.pythonhosted.org/packages/e1/1e/5a4441be21b0726c4464f3f23c8b19628372f606755a9d2e46c187e65ec4/async_timeout-3.0.1-py3-none-any.whl\n", | |
"Requirement already satisfied: idna>=2.0 in /usr/local/lib/python3.6/dist-packages (from idna-ssl>=1.0; python_version < \"3.7\"->aiohttp) (2.10)\n", | |
"Building wheels for collected packages: idna-ssl\n", | |
" Building wheel for idna-ssl (setup.py) ... \u001b[?25l\u001b[?25hdone\n", | |
" Created wheel for idna-ssl: filename=idna_ssl-1.1.0-cp36-none-any.whl size=3162 sha256=5933eb4288935d2ade0a2241a3dc2cd7e6b2ccd95bbbec28908f07c69d588dc4\n", | |
" Stored in directory: /root/.cache/pip/wheels/d3/00/b3/32d613e19e08a739751dd6bf998cfed277728f8b2127ad4eb7\n", | |
"Successfully built idna-ssl\n", | |
"Installing collected packages: multidict, idna-ssl, yarl, async-timeout, aiohttp\n", | |
"Successfully installed aiohttp-3.6.2 async-timeout-3.0.1 idna-ssl-1.1.0 multidict-4.7.6 yarl-1.5.1\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "NN4wIaCsHABl", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"import asyncio\n", | |
"from aiohttp import ClientSession\n", | |
"import nest_asyncio\n", | |
"nest_asyncio.apply()\n", | |
"loop = asyncio.get_event_loop()\n", | |
"\n", | |
"async def hello(url):\n", | |
" async with ClientSession() as session:\n", | |
" async with session.get(url) as response:\n", | |
" response = response.read()\n", | |
" # print(response)\n", | |
"\n", | |
" \n", | |
"# tasks = []\n", | |
"\n", | |
"url = \"http://example.com/\"\n", | |
"for i in range(1000):\n", | |
" print('Request no',i)\n", | |
" task = asyncio.ensure_future(hello(url.format(i)))\n", | |
" # tasks.append(task)\n", | |
"# loop.run_until_complete(asyncio.wait(tasks))" | |
], | |
"execution_count": null, | |
"outputs": [] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment