{"id":764,"date":"2024-05-06T01:02:53","date_gmt":"2024-05-05T16:02:53","guid":{"rendered":"https:\/\/chocottopro.com\/?p=764"},"modified":"2024-05-06T01:02:54","modified_gmt":"2024-05-05T16:02:54","slug":"%e3%80%90python%e3%80%91asyncio%e3%83%9e%e3%82%b9%e3%82%bf%e3%83%bc%e3%81%b8%e3%81%ae%e9%81%93%ef%bc%9a%e9%9d%9e%e5%90%8c%e6%9c%9f%e3%83%97%e3%83%ad%e3%82%b0%e3%83%a9%e3%83%9f%e3%83%b3%e3%82%b0","status":"publish","type":"post","link":"https:\/\/chocottopro.com\/?p=764","title":{"rendered":"\u3010Python\u3011asyncio\u30de\u30b9\u30bf\u30fc\u3078\u306e\u9053\uff1a\u975e\u540c\u671f\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u3092\u52b9\u7387\u7684\u306b\u5b66\u30767\u3064\u306e\u30b9\u30c6\u30c3\u30d7"},"content":{"rendered":"\n<p>Python\u306e\u975e\u540c\u671f\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u30e9\u30a4\u30d6\u30e9\u30ea\u300casyncio\u300d\u306f\u3001\u9ad8\u6027\u80fd\u306a\u4e26\u884c\u51e6\u7406\u3092\u5b9f\u73fe\u3059\u308b\u305f\u3081\u306e\u5f37\u529b\u306a\u30c4\u30fc\u30eb\u3067\u3059\u3002\u3057\u304b\u3057\u3001asyncio\u3092\u52b9\u679c\u7684\u306b\u4f7f\u3044\u3053\u306a\u3059\u306b\u306f\u3001\u975e\u540c\u671f\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u306e\u6982\u5ff5\u3084\u7279\u6027\u3092\u7406\u89e3\u3057\u3001\u9069\u5207\u306a\u8a2d\u8a08\u3068\u5b9f\u88c5\u304c\u6c42\u3081\u3089\u308c\u307e\u3059\u3002\u672c\u8a18\u4e8b\u3067\u306f\u3001asyncio\u306e\u57fa\u790e\u77e5\u8b58\u304b\u3089\u5b9f\u8df5\u7684\u306a\u30b3\u30fc\u30c9\u4f8b\u3001\u30d9\u30b9\u30c8\u30d7\u30e9\u30af\u30c6\u30a3\u30b9\u307e\u3067\u3001asyncio\u30de\u30b9\u30bf\u30fc\u3078\u306e\u9053\u306e\u308a\u3092\u6bb5\u968e\u7684\u306b\u89e3\u8aac\u3057\u307e\u3059\u3002\u975e\u540c\u671f\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u306e\u30b9\u30ad\u30eb\u3092\u8eab\u306b\u3064\u3051\u3001\u30ad\u30e3\u30ea\u30a2\u30a2\u30c3\u30d7\u3092\u76ee\u6307\u3059\u958b\u767a\u8005\u5fc5\u898b\u306e\u5185\u5bb9\u3068\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"wp-block-sgb-block-simple sgb-box-simple sgb-box-simple--title-normal sgb-box-simple--with-border\"><div style=\"background-color:var(--wp--preset--color--sango-main);color:#FFF\" class=\"sgb-box-simple__title\">\u3053\u306e\u8a18\u4e8b\u3092\u8aad\u3093\u3060\u3089\u308f\u304b\u308b\u3053\u3068<\/div><div class=\"sgb-box-simple__body\" style=\"border-color:var(--wp--preset--color--sango-main);background-color:#FFF\">\n<ul class=\"wp-block-list\">\n<li>asyncio\u306e\u6982\u8981\u3068\u975e\u540c\u671f\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u306e\u57fa\u790e\u77e5\u8b58 <\/li>\n\n\n\n<li>asyncio\u306e\u57fa\u672c\u7684\u306a\u4f7f\u3044\u65b9\u3068\u3001async\/await\u30ad\u30fc\u30ef\u30fc\u30c9\u306e\u5f79\u5272 <\/li>\n\n\n\n<li>\u5b9f\u8df5\u7684\u306a\u30b3\u30fc\u30c9\u4f8b\u3092\u901a\u3058\u305fasyncio\u306e\u6d3b\u7528\u65b9\u6cd5 <\/li>\n\n\n\n<li>asyncio\u3092\u4f7f\u3046\u4e0a\u3067\u306e\u30d9\u30b9\u30c8\u30d7\u30e9\u30af\u30c6\u30a3\u30b9\u3068Tips asyncio\u3092\u5fdc\u7528\u3057\u305f\u3001\u9ad8\u6027\u80fd\u306a\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u958b\u767a\u306e\u4e8b\u4f8b <\/li>\n\n\n\n<li>asyncio\u3092\u5b66\u3076\u305f\u3081\u306e\u52b9\u679c\u7684\u306a\u5b66\u7fd2\u30ea\u30bd\u30fc\u30b9\u3068\u53c2\u8003\u60c5\u5831 <\/li>\n\n\n\n<li>asyncio\u30de\u30b9\u30bf\u30fc\u306b\u306a\u308b\u305f\u3081\u306b\u5fc5\u8981\u306a\u5fc3\u69cb\u3048\u3068\u30b9\u30ad\u30eb\u5411\u4e0a\u306e\u65b9\u6cd5<\/li>\n<\/ul>\n<\/div><\/div>\n\n\n\n<div class=\"toc\"><br \/>\n<b>Warning<\/b>:  Undefined array key \"is_admin\" in <b>\/home\/c7479301\/public_html\/chocottopro.com\/wp-content\/themes\/sango-theme\/library\/gutenberg\/dist\/classes\/Toc.php<\/b> on line <b>116<\/b><br \/>\n<br \/>\n<b>Warning<\/b>:  Undefined array key \"is_category_top\" in <b>\/home\/c7479301\/public_html\/chocottopro.com\/wp-content\/themes\/sango-theme\/library\/gutenberg\/dist\/classes\/Toc.php<\/b> on line <b>121<\/b><br \/>\n<br \/>\n<b>Warning<\/b>:  Undefined array key \"is_top\" in <b>\/home\/c7479301\/public_html\/chocottopro.com\/wp-content\/themes\/sango-theme\/library\/gutenberg\/dist\/classes\/Toc.php<\/b> on line <b>128<\/b><br \/>\n    <div id=\"toc_container\" class=\"sgb-toc--bullets js-smooth-scroll\" data-dialog-title=\"Table of Contents\">\n      <p class=\"toc_title\">\u76ee\u6b21 <\/p>\n      <ul class=\"toc_list\">  <li class=\"first\">    <a href=\"#i-0\">asyncio\u3068\u306f\uff1f\u975e\u540c\u671f\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u306e\u57fa\u790e\u77e5\u8b58<\/a>    <ul class=\"menu_level_1\">      <li class=\"first\">        <a href=\"#i-1\">asyncio\u306e\u6982\u8981\u3068\u7279\u5fb4<\/a>      <\/li>      <li>        <a href=\"#i-2\">\u975e\u540c\u671f\u51e6\u7406\u306e\u4ed5\u7d44\u307f\u3068\u5229\u70b9<\/a>      <\/li>      <li class=\"last\">        <a href=\"#i-3\">asyncio\u3068\u30de\u30eb\u30c1\u30b9\u30ec\u30c3\u30c9\u306e\u9055\u3044<\/a>      <\/li>    <\/ul>  <\/li>  <li>    <a href=\"#i-4\">asyncio\u306e\u57fa\u672c\u7684\u306a\u4f7f\u3044\u65b9<\/a>    <ul class=\"menu_level_1\">      <li class=\"first\">        <a href=\"#i-5\">asyncio\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3068\u74b0\u5883\u8a2d\u5b9a<\/a>      <\/li>      <li>        <a href=\"#i-6\">async\/await\u30ad\u30fc\u30ef\u30fc\u30c9\u306e\u4f7f\u3044\u65b9<\/a>      <\/li>      <li class=\"last\">        <a href=\"#i-7\">\u30a4\u30d9\u30f3\u30c8\u30eb\u30fc\u30d7\u306e\u7406\u89e3\u3068\u5236\u5fa1<\/a>      <\/li>    <\/ul>  <\/li>  <li>    <a href=\"#i-8\">asyncio\u3092\u4f7f\u3063\u305f\u5b9f\u8df5\u7684\u306a\u30b3\u30fc\u30c9\u4f8b<\/a>    <ul class=\"menu_level_1\">      <li class=\"first\">        <a href=\"#i-9\">\u975e\u540c\u671fHTTP\u30ea\u30af\u30a8\u30b9\u30c8\u306e\u9001\u4fe1<\/a>      <\/li>      <li>        <a href=\"#i-10\">\u975e\u540c\u671fDB\u30a2\u30af\u30bb\u30b9\u306e\u5b9f\u88c5<\/a>      <\/li>      <li class=\"last\">        <a href=\"#i-11\">WebSocket\u3092\u4f7f\u3063\u305f\u30ea\u30a2\u30eb\u30bf\u30a4\u30e0\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3<\/a>      <\/li>    <\/ul>  <\/li>  <li>    <a href=\"#i-12\">asyncio\u306e\u30d9\u30b9\u30c8\u30d7\u30e9\u30af\u30c6\u30a3\u30b9\u3068Tips<\/a>    <ul class=\"menu_level_1\">      <li class=\"first\">        <a href=\"#i-13\">\u4f8b\u5916\u51e6\u7406\u3068\u30a8\u30e9\u30fc\u30cf\u30f3\u30c9\u30ea\u30f3\u30b0<\/a>      <\/li>      <li>        <a href=\"#i-14\">\u30c7\u30d0\u30c3\u30b0\u3068\u30ed\u30b0\u51fa\u529b\u306e\u30c6\u30af\u30cb\u30c3\u30af<\/a>      <\/li>      <li class=\"last\">        <a href=\"#i-15\">\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u6539\u5584\u306e\u305f\u3081\u306e\u8a2d\u8a08\u3068\u5b9f\u88c5<\/a>      <\/li>    <\/ul>  <\/li>  <li>    <a href=\"#i-16\">asyncio\u3092\u4f7f\u3063\u305f\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u958b\u767a\u4e8b\u4f8b<\/a>    <ul class=\"menu_level_1\">      <li class=\"first\">        <a href=\"#i-17\">\u9ad8\u30c8\u30e9\u30d5\u30a3\u30c3\u30af\u306b\u8010\u3048\u308bWeb\u30b5\u30fc\u30d0\u30fc\u306e\u69cb\u7bc9<\/a>      <\/li>      <li>        <a href=\"#i-18\">\u5927\u91cf\u306e\u30bf\u30b9\u30af\u3092\u52b9\u7387\u7684\u306b\u51e6\u7406\u3059\u308b\u30b8\u30e7\u30d6\u30ad\u30e5\u30fc<\/a>      <\/li>      <li class=\"last\">        <a href=\"#i-19\">\u30ea\u30a2\u30eb\u30bf\u30a4\u30e0\u6027\u304c\u6c42\u3081\u3089\u308c\u308b\u30c1\u30e3\u30c3\u30c8\u30a2\u30d7\u30ea\u306e\u958b\u767a<\/a>      <\/li>    <\/ul>  <\/li>  <li>    <a href=\"#i-20\">asyncio\u306e\u5b66\u7fd2\u30ea\u30bd\u30fc\u30b9\u3068\u53c2\u8003\u60c5\u5831<\/a>    <ul class=\"menu_level_1\">      <li class=\"first\">        <a href=\"#i-21\">\u516c\u5f0f\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u3068\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb<\/a>      <\/li>      <li>        <a href=\"#i-22\">\u304a\u3059\u3059\u3081\u306e\u66f8\u7c4d<\/a>      <\/li>      <li class=\"last\">        <a href=\"#i-23\">asyncio\u3092\u4f7f\u3044\u3053\u306a\u3059\u305f\u3081\u306e\u7d99\u7d9a\u7684\u306a\u5b66\u7fd2\u65b9\u6cd5<\/a>      <\/li>    <\/ul>  <\/li>  <li class=\"last\">    <a href=\"#i-24\">\u307e\u3068\u3081\uff1aasyncio\u30de\u30b9\u30bf\u30fc\u306b\u306a\u308b\u305f\u3081\u306b<\/a>    <ul class=\"menu_level_1\">      <li class=\"first\">        <a href=\"#i-25\">asyncio\u3092\u5b66\u3076\u610f\u7fa9\u3068\u5c06\u6765\u6027<\/a>      <\/li>      <li>        <a href=\"#i-26\">\u975e\u540c\u671f\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u30b9\u30ad\u30eb\u304c\u6d3b\u304b\u305b\u308b\u9818\u57df\u3068\u4ed5\u4e8b<\/a>      <\/li>      <li class=\"last\">        <a href=\"#i-27\">asyncio\u30de\u30b9\u30bf\u30fc\u3078\u306e\u9053\u306e\u308a\uff1a\u7d99\u7d9a\u7684\u306a\u5b66\u7fd2\u3068\u5b9f\u8df5\u306e\u91cd\u8981\u6027<\/a>      <\/li>    <\/ul>  <\/li><\/ul>\n      \n    <\/div><\/div><h2 class=\"wp-block-heading\" id=\"i-0\">asyncio\u3068\u306f\uff1f\u975e\u540c\u671f\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u306e\u57fa\u790e\u77e5\u8b58<\/h2>\n\n\n\n<p>Python\u306e\u6a19\u6e96\u30e9\u30a4\u30d6\u30e9\u30ea\u3067\u3042\u308basyncio\u306f\u3001\u975e\u540c\u671fI\/O\u3092\u4f7f\u3063\u305f\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u3092\u884c\u3046\u305f\u3081\u306e\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u3067\u3059\u3002asyncio\u3092\u4f7f\u3046\u3053\u3068\u3067\u3001I\/O bound\u306a\u51e6\u7406\u3092\u52b9\u7387\u7684\u306b\u884c\u3044\u3001\u9ad8\u3044\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u3092\u5b9f\u73fe\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-1\">asyncio\u306e\u6982\u8981\u3068\u7279\u5fb4<\/h3>\n\n\n\n<p>asyncio\u306f\u3001Python 3.4\u4ee5\u964d\u306b\u6a19\u6e96\u30e9\u30a4\u30d6\u30e9\u30ea\u3068\u3057\u3066\u5c0e\u5165\u3055\u308c\u307e\u3057\u305f\u3002\u975e\u540c\u671f\u51e6\u7406\u3092\u4f7f\u3063\u3066I\/O bound\u306a\u51e6\u7406\u3092\u52b9\u7387\u7684\u306b\u884c\u3046\u3053\u3068\u304c\u3067\u304d\u3001\u30b3\u30eb\u30fc\u30c1\u30f3\uff08coroutine\uff09\u3001\u30a4\u30d9\u30f3\u30c8\u30eb\u30fc\u30d7\u3001\u30bf\u30b9\u30af\u3001\u30d5\u30e5\u30fc\u30c1\u30e3\u30fc\u306a\u3069\u306e\u6982\u5ff5\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002asyncio\u3092\u4f7f\u3046\u3053\u3068\u3067\u3001\u30b7\u30f3\u30b0\u30eb\u30b9\u30ec\u30c3\u30c9\u3067\u306e\u4e26\u884c\u51e6\u7406\u304c\u53ef\u80fd\u306b\u306a\u308a\u3001\u9ad8\u3044\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u3092\u5b9f\u73fe\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-2\">\u975e\u540c\u671f\u51e6\u7406\u306e\u4ed5\u7d44\u307f\u3068\u5229\u70b9<\/h3>\n\n\n\n<p>\u975e\u540c\u671f\u51e6\u7406\u3067\u306f\u3001I\/O\u51e6\u7406\u306e\u5f85\u3061\u6642\u9593\u4e2d\u306b\u4ed6\u306e\u51e6\u7406\u3092\u5b9f\u884c\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u3053\u308c\u306b\u3088\u308a\u3001\u30d6\u30ed\u30c3\u30ad\u30f3\u30b0I\/O\u3067\u306f\u306a\u304f\u3001\u30ce\u30f3\u30d6\u30ed\u30c3\u30ad\u30f3\u30b0I\/O\u3092\u4f7f\u7528\u3057\u3001\u30b3\u30fc\u30eb\u30d0\u30c3\u30af\u95a2\u6570\u3084\u30a4\u30d9\u30f3\u30c8\u30eb\u30fc\u30d7\u3092\u4f7f\u3063\u3066\u51e6\u7406\u306e\u6d41\u308c\u3092\u5236\u5fa1\u3057\u307e\u3059\u3002\u30b9\u30ec\u30c3\u30c9\u3084\u30d7\u30ed\u30bb\u30b9\u306e\u30aa\u30fc\u30d0\u30fc\u30d8\u30c3\u30c9\u3092\u907f\u3051\u3001\u30ea\u30bd\u30fc\u30b9\u3092\u52b9\u7387\u7684\u306b\u5229\u7528\u53ef\u80fd\u3067\u3059\u3002\u7279\u306b\u3001\u30d5\u30a1\u30a4\u30ebI\/O\u3084\u30cd\u30c3\u30c8\u30ef\u30fc\u30afI\/O\u306a\u3069\u306e I\/O bound \u306a\u51e6\u7406\u3067\u5927\u304d\u306a\u5a01\u529b\u3092\u767a\u63ee\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u4f8b\u3048\u3070\u3001\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u306f\u3001asyncio\u3092\u4f7f\u3063\u3066\u975e\u540c\u671f\u306bHTTP\u30ea\u30af\u30a8\u30b9\u30c8\u3092\u9001\u4fe1\u3059\u308b\u4f8b\u3067\u3059\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import asyncio\nimport aiohttp\n\nasync def fetch(url):\n    async with aiohttp.ClientSession() as session:\n        async with session.get(url) as response:\n            return await response.text()\n\nasync def main():\n    urls = [\n        'https:\/\/www.example.com',\n        'https:\/\/www.example.org',\n        'https:\/\/www.example.net'\n    ]\n    tasks = []\n    for url in urls:\n        tasks.append(asyncio.create_task(fetch(url)))\n\n    results = await asyncio.gather(*tasks)\n    for result in results:\n        print(result[:100])  # \u6700\u521d\u306e100\u6587\u5b57\u3092\u8868\u793a\n\nasyncio.run(main())<\/pre>\n\n\n\n<p>\u3053\u306e\u4f8b\u3067\u306f\u3001<code>aiohttp<\/code>\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u4f7f\u7528\u3057\u3066\u975e\u540c\u671fHTTP\u30ea\u30af\u30a8\u30b9\u30c8\u3092\u9001\u4fe1\u3057\u3066\u3044\u307e\u3059\u3002<code>fetch<\/code>\u95a2\u6570\u306f\u3001URL\u3092\u53d7\u3051\u53d6\u308a\u3001\u975e\u540c\u671f\u306bHTTP\u30ea\u30af\u30a8\u30b9\u30c8\u3092\u9001\u4fe1\u3057\u3066\u7d50\u679c\u3092\u8fd4\u3057\u307e\u3059\u3002<code>main<\/code>\u95a2\u6570\u3067\u306f\u3001\u8907\u6570\u306eURL\u306b\u5bfe\u3057\u3066<code>fetch<\/code>\u95a2\u6570\u3092\u30bf\u30b9\u30af\u3068\u3057\u3066\u4f5c\u6210\u3057\u3001<code>asyncio.gather<\/code>\u3092\u4f7f\u3063\u3066\u4e26\u884c\u306b\u5b9f\u884c\u3057\u307e\u3059\u3002\u6700\u5f8c\u306b\u3001\u7d50\u679c\u3092\u8868\u793a\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-3\">asyncio\u3068\u30de\u30eb\u30c1\u30b9\u30ec\u30c3\u30c9\u306e\u9055\u3044<\/h3>\n\n\n\n<p>\u30de\u30eb\u30c1\u30b9\u30ec\u30c3\u30c9\u306f\u8907\u6570\u306e\u30b9\u30ec\u30c3\u30c9\u3092\u4f7f\u3063\u3066\u4e26\u884c\u51e6\u7406\u3092\u884c\u3046\u624b\u6cd5\u3067\u3059\u304c\u3001asyncio\u306f\u30b7\u30f3\u30b0\u30eb\u30b9\u30ec\u30c3\u30c9\u3067\u52d5\u4f5c\u3057\u3001\u30b3\u30eb\u30fc\u30c1\u30f3\u3092\u4f7f\u3063\u3066\u5354\u8abf\u7684\u30de\u30eb\u30c1\u30bf\u30b9\u30af\u3092\u5b9f\u73fe\u3057\u307e\u3059\u3002\u30de\u30eb\u30c1\u30b9\u30ec\u30c3\u30c9\u3067\u306f\u30b9\u30ec\u30c3\u30c9\u9593\u306e\u540c\u671f\u3084\u7af6\u5408\u306e\u554f\u984c\u3092\u8003\u616e\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u304c\u3001asyncio\u3067\u306f\u30b7\u30f3\u30b0\u30eb\u30b9\u30ec\u30c3\u30c9\u3067\u52d5\u4f5c\u3059\u308b\u305f\u3081\u3001\u30b9\u30ec\u30c3\u30c9\u30bb\u30fc\u30d5\u306a\u8a2d\u8a08\u304c\u4e0d\u8981\u3067\u3059\u3002\u307e\u305f\u3001\u30de\u30eb\u30c1\u30b9\u30ec\u30c3\u30c9\u3088\u308a\u3082\u30aa\u30fc\u30d0\u30fc\u30d8\u30c3\u30c9\u304c\u5c11\u306a\u304f\u3001\u5927\u91cf\u306e\u4e26\u884c\u51e6\u7406\u306b\u9069\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p>asyncio\u306f\u3001I\/O bound\u306a\u51e6\u7406\u3092\u52b9\u7387\u7684\u306b\u884c\u3046\u3053\u3068\u304c\u3067\u304d\u3001Web\u30b5\u30fc\u30d0\u30fc\u3001API\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u3001\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u30a2\u30af\u30bb\u30b9\u306a\u3069\u3001\u69d8\u3005\u306a\u5834\u9762\u3067\u6d3b\u7528\u3055\u308c\u3066\u3044\u307e\u3059\u3002\u975e\u540c\u671f\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u306e\u57fa\u790e\u77e5\u8b58\u3092\u8eab\u306b\u3064\u3051\u308b\u3053\u3068\u3067\u3001\u3088\u308a\u9ad8\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u306a\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u958b\u767a\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3067\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"i-4\">asyncio\u306e\u57fa\u672c\u7684\u306a\u4f7f\u3044\u65b9<\/h2>\n\n\n\n<p>asyncio\u3092\u4f7f\u3063\u305f\u975e\u540c\u671f\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u3092\u59cb\u3081\u308b\u305f\u3081\u306b\u3001\u307e\u305a\u306fasyncio\u306e\u57fa\u672c\u7684\u306a\u4f7f\u3044\u65b9\u3092\u7406\u89e3\u3057\u307e\u3057\u3087\u3046\u3002\u3053\u3053\u3067\u306f\u3001asyncio\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3068\u74b0\u5883\u8a2d\u5b9a\u3001async\/await\u30ad\u30fc\u30ef\u30fc\u30c9\u306e\u4f7f\u3044\u65b9\u3001\u30a4\u30d9\u30f3\u30c8\u30eb\u30fc\u30d7\u306e\u7406\u89e3\u3068\u5236\u5fa1\u306b\u3064\u3044\u3066\u8aac\u660e\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-5\">asyncio\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3068\u74b0\u5883\u8a2d\u5b9a<\/h3>\n\n\n\n<p>asyncio\u3092\u4f7f\u3046\u306b\u306f\u3001Python 3.4\u4ee5\u964d\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u304c\u5fc5\u8981\u3067\u3059\u3002asyncio\u306f\u6a19\u6e96\u30e9\u30a4\u30d6\u30e9\u30ea\u306b\u542b\u307e\u308c\u3066\u3044\u308b\u305f\u3081\u3001\u8ffd\u52a0\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u306f\u4e0d\u8981\u3067\u3001<code>import asyncio<\/code>\u3067\u7c21\u5358\u306b\u5229\u7528\u53ef\u80fd\u3067\u3059\u3002\u307e\u305f\u3001Python 3.7\u4ee5\u964d\u3067\u306f\u3001<code>asyncio.run()<\/code>\u3092\u4f7f\u3063\u3066\u30a4\u30d9\u30f3\u30c8\u30eb\u30fc\u30d7\u3092\u7c21\u5358\u306b\u5b9f\u884c\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-6\">async\/await\u30ad\u30fc\u30ef\u30fc\u30c9\u306e\u4f7f\u3044\u65b9<\/h3>\n\n\n\n<p>asyncio\u3067\u306f\u3001<code>async def<\/code>\u3092\u4f7f\u3063\u3066\u30b3\u30eb\u30fc\u30c1\u30f3\u3092\u5b9a\u7fa9\u3057\u307e\u3059\u3002\u30b3\u30eb\u30fc\u30c1\u30f3\u306f\u3001<code>await<\/code>\u3092\u4f7f\u3063\u3066\u5b9f\u884c\u3092\u4e00\u6642\u505c\u6b62\u3057\u3001\u4ed6\u306e\u30b3\u30eb\u30fc\u30c1\u30f3\u306b\u5236\u5fa1\u3092\u8b72\u6e21\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<code>await<\/code>\u306f\u3001<code>async def<\/code>\u3067\u5b9a\u7fa9\u3055\u308c\u305f\u95a2\u6570\u5185\u3067\u306e\u307f\u4f7f\u7528\u53ef\u80fd\u3067\u3059\u3002\u30b3\u30eb\u30fc\u30c1\u30f3\u306f\u3001<code>asyncio.create_task()<\/code>\u3092\u4f7f\u3063\u3066\u30bf\u30b9\u30af\u3068\u3057\u3066\u5b9f\u884c\u3055\u308c\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import asyncio\n\nasync def fetch_data(url):\n    print(f'Fetching data from {url}')\n    await asyncio.sleep(1)  # \u975e\u540c\u671f\u51e6\u7406\u3092\u6a21\u64ec\n    print(f'Data fetched from {url}')\n    return f'Data from {url}'\n\nasync def main():\n    urls = ['https:\/\/example.com', 'https:\/\/example.org', 'https:\/\/example.net']\n    tasks = []\n    for url in urls:\n        tasks.append(asyncio.create_task(fetch_data(url)))\n\n    results = await asyncio.gather(*tasks)\n    print(results)\n\nasyncio.run(main())<\/pre>\n\n\n\n<p>\u60f3\u5b9a\u3055\u308c\u308b\u51fa\u529b\u7d50\u679c:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">Fetching data from https:\/\/example.com\nFetching data from https:\/\/example.org\nFetching data from https:\/\/example.net\nData fetched from https:\/\/example.com\nData fetched from https:\/\/example.org\nData fetched from https:\/\/example.net\n['Data from https:\/\/example.com', 'Data from https:\/\/example.org', 'Data from https:\/\/example.net']<\/pre>\n\n\n\n<p>\u3053\u306e\u4f8b\u3067\u306f\u3001<code>fetch_data<\/code>\u30b3\u30eb\u30fc\u30c1\u30f3\u3092\u5b9a\u7fa9\u3057\u3001URL\u304b\u3089\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3059\u308b\u975e\u540c\u671f\u51e6\u7406\u3092\u6a21\u64ec\u3057\u3066\u3044\u307e\u3059\u3002<code>main<\/code>\u30b3\u30eb\u30fc\u30c1\u30f3\u3067\u306f\u3001\u8907\u6570\u306eURL\u306b\u5bfe\u3057\u3066<code>fetch_data<\/code>\u30b3\u30eb\u30fc\u30c1\u30f3\u3092\u30bf\u30b9\u30af\u3068\u3057\u3066\u4f5c\u6210\u3057\u3001<code>asyncio.gather<\/code>\u3092\u4f7f\u3063\u3066\u4e26\u884c\u306b\u5b9f\u884c\u3057\u3066\u3044\u307e\u3059\u3002\u6700\u5f8c\u306b\u3001\u7d50\u679c\u3092\u8868\u793a\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-7\">\u30a4\u30d9\u30f3\u30c8\u30eb\u30fc\u30d7\u306e\u7406\u89e3\u3068\u5236\u5fa1<\/h3>\n\n\n\n<p>\u30a4\u30d9\u30f3\u30c8\u30eb\u30fc\u30d7\u306f\u3001asyncio\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u4e2d\u5fc3\u7684\u306a\u5b58\u5728\u3067\u3001\u30bf\u30b9\u30af\u306e\u5b9f\u884c\u3084I\/O\u51e6\u7406\u306e\u7ba1\u7406\u3092\u884c\u3044\u307e\u3059\u3002<code>asyncio.get_event_loop()<\/code>\u3092\u4f7f\u3063\u3066\u3001\u73fe\u5728\u306e\u30a4\u30d9\u30f3\u30c8\u30eb\u30fc\u30d7\u3092\u53d6\u5f97\u3067\u304d\u307e\u3059\u3002<code>loop.run_until_complete()<\/code>\u3092\u4f7f\u3063\u3066\u3001\u30a4\u30d9\u30f3\u30c8\u30eb\u30fc\u30d7\u3092\u5b9f\u884c\u3057\u307e\u3059\u3002Python 3.7\u4ee5\u964d\u3067\u306f\u3001<code>asyncio.run()<\/code>\u3092\u4f7f\u3063\u3066\u7c21\u5358\u306b\u30a4\u30d9\u30f3\u30c8\u30eb\u30fc\u30d7\u3092\u5b9f\u884c\u53ef\u80fd\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import asyncio\n\nasync def my_coroutine():\n    print('Coroutine started')\n    await asyncio.sleep(1)\n    print('Coroutine finished')\n\nasync def main():\n    await my_coroutine()\n\nasyncio.run(main())<\/pre>\n\n\n\n<p>\u60f3\u5b9a\u3055\u308c\u308b\u51fa\u529b\u7d50\u679c:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">Coroutine started\nCoroutine finished<\/pre>\n\n\n\n<p>\u3053\u306e\u4f8b\u3067\u306f\u3001<code>my_coroutine<\/code>\u30b3\u30eb\u30fc\u30c1\u30f3\u3092\u5b9a\u7fa9\u3057\u30011\u79d2\u9593\u306e\u975e\u540c\u671f\u51e6\u7406\u3092\u6a21\u64ec\u3057\u3066\u3044\u307e\u3059\u3002<code>main<\/code>\u30b3\u30eb\u30fc\u30c1\u30f3\u3067\u306f\u3001<code>my_coroutine<\/code>\u3092\u547c\u3073\u51fa\u3057\u3001<code>asyncio.run()<\/code>\u3092\u4f7f\u3063\u3066\u30a4\u30d9\u30f3\u30c8\u30eb\u30fc\u30d7\u3092\u5b9f\u884c\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p>asyncio\u306e\u57fa\u672c\u7684\u306a\u4f7f\u3044\u65b9\u3092\u7406\u89e3\u3059\u308b\u3053\u3068\u3067\u3001\u975e\u540c\u671f\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u306e\u57fa\u790e\u3092\u8eab\u306b\u3064\u3051\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u6b21\u306e\u30bb\u30af\u30b7\u30e7\u30f3\u3067\u306f\u3001\u3088\u308a\u5b9f\u8df5\u7684\u306a\u30b3\u30fc\u30c9\u4f8b\u3092\u901a\u3058\u3066\u3001asyncio\u306e\u6d3b\u7528\u65b9\u6cd5\u3092\u5b66\u3073\u307e\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"i-8\">asyncio\u3092\u4f7f\u3063\u305f\u5b9f\u8df5\u7684\u306a\u30b3\u30fc\u30c9\u4f8b<\/h2>\n\n\n\n<p>asyncio\u3092\u4f7f\u3063\u305f\u975e\u540c\u671f\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u306e\u5b9f\u8df5\u7684\u306a\u30b3\u30fc\u30c9\u4f8b\u3092\u898b\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002\u3053\u3053\u3067\u306f\u3001\u975e\u540c\u671fHTTP\u30ea\u30af\u30a8\u30b9\u30c8\u306e\u9001\u4fe1\u3001\u975e\u540c\u671fDB\u30a2\u30af\u30bb\u30b9\u306e\u5b9f\u88c5\u3001WebSocket\u3092\u4f7f\u3063\u305f\u30ea\u30a2\u30eb\u30bf\u30a4\u30e0\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e3\u3064\u306e\u4f8b\u3092\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-9\">\u975e\u540c\u671fHTTP\u30ea\u30af\u30a8\u30b9\u30c8\u306e\u9001\u4fe1<\/h3>\n\n\n\n<p><code>aiohttp<\/code>\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u4f7f\u7528\u3059\u308b\u3068\u3001\u975e\u540c\u671fHTTP\u30ea\u30af\u30a8\u30b9\u30c8\u3092\u7c21\u5358\u306b\u9001\u4fe1\u3067\u304d\u307e\u3059\u3002<code>aiohttp.ClientSession<\/code>\u3092\u4f7f\u3063\u3066HTTP\u30bb\u30c3\u30b7\u30e7\u30f3\u3092\u4f5c\u6210\u3057\u3001<code>session.get()<\/code>\u3001<code>session.post()<\/code>\u306a\u3069\u306e\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u3063\u3066\u3001\u975e\u540c\u671f\u30ea\u30af\u30a8\u30b9\u30c8\u3092\u9001\u4fe1\u3057\u307e\u3059\u3002\u30ec\u30b9\u30dd\u30f3\u30b9\u306e\u51e6\u7406\u306f\u3001<code>await<\/code>\u3092\u4f7f\u3063\u3066\u975e\u540c\u671f\u306b\u884c\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import asyncio\nimport aiohttp\n\nasync def fetch(url):\n    async with aiohttp.ClientSession() as session:\n        async with session.get(url) as response:\n            return await response.json()\n\nasync def main():\n    urls = [\n        'https:\/\/api.github.com\/repos\/python\/cpython',\n        'https:\/\/api.github.com\/repos\/python\/peps',\n    ]\n    tasks = []\n    for url in urls:\n        tasks.append(asyncio.create_task(fetch(url)))\n\n    results = await asyncio.gather(*tasks)\n    for result in results:\n        print(f\"Repository: {result['full_name']}, Stars: {result['stargazers_count']}\")\n\nasyncio.run(main())<\/pre>\n\n\n\n<p>\u3053\u306e\u4f8b\u3067\u306f\u3001GitHub\u306eAPI\u3092\u4f7f\u3063\u3066\u3001Python\u306eCPython\u3068PEPs\u30ea\u30dd\u30b8\u30c8\u30ea\u306e\u60c5\u5831\u3092\u975e\u540c\u671f\u306b\u53d6\u5f97\u3057\u3066\u3044\u307e\u3059\u3002<code>fetch<\/code>\u95a2\u6570\u3067\u5404\u30ea\u30dd\u30b8\u30c8\u30ea\u306e\u60c5\u5831\u3092\u53d6\u5f97\u3057\u3001<code>main<\/code>\u95a2\u6570\u3067\u8907\u6570\u306eURL\u306b\u5bfe\u3057\u3066<code>fetch<\/code>\u95a2\u6570\u3092\u30bf\u30b9\u30af\u3068\u3057\u3066\u4f5c\u6210\u3057\u3001<code>asyncio.gather<\/code>\u3092\u4f7f\u3063\u3066\u4e26\u884c\u306b\u5b9f\u884c\u3057\u3066\u3044\u307e\u3059\u3002\u6700\u5f8c\u306b\u3001\u7d50\u679c\u3092\u8868\u793a\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-10\">\u975e\u540c\u671fDB\u30a2\u30af\u30bb\u30b9\u306e\u5b9f\u88c5<\/h3>\n\n\n\n<p><code>asyncpg<\/code>\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u4f7f\u7528\u3059\u308b\u3068\u3001PostgreSQL\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306b\u975e\u540c\u671f\u30a2\u30af\u30bb\u30b9\u3067\u304d\u307e\u3059\u3002<code>asyncpg.create_pool()<\/code>\u3092\u4f7f\u3063\u3066\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u63a5\u7d9a\u30d7\u30fc\u30eb\u3092\u4f5c\u6210\u3057\u3001<code>pool.fetch()<\/code>\u3001<code>pool.execute()<\/code>\u306a\u3069\u306e\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u3063\u3066\u3001\u975e\u540c\u671f\u30af\u30a8\u30ea\u3092\u5b9f\u884c\u3057\u307e\u3059\u3002\u30af\u30a8\u30ea\u306e\u7d50\u679c\u306f\u3001<code>await<\/code>\u3092\u4f7f\u3063\u3066\u975e\u540c\u671f\u306b\u51e6\u7406\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import asyncio\nimport asyncpg\n\nasync def main():\n    pool = await asyncpg.create_pool(\n        host='localhost',\n        port=5432,\n        user='user',\n        password='password',\n        database='mydatabase'\n    )\n\n    async with pool.acquire() as conn:\n        await conn.execute('''\n            CREATE TABLE IF NOT EXISTS products (\n                id SERIAL PRIMARY KEY,\n                name TEXT NOT NULL,\n                price DECIMAL(10, 2) NOT NULL\n            )\n        ''')\n\n        await conn.execute('''\n            INSERT INTO products(name, price) VALUES($1, $2)\n        ''', 'iPhone 12', 999.99)\n\n    async with pool.acquire() as conn:\n        rows = await conn.fetch('SELECT * FROM products')\n        for row in rows:\n            print(f\"Product: {row['name']}, Price: {row['price']}\")\n\n    await pool.close()\n\nasyncio.run(main())<\/pre>\n\n\n\n<p>\u3053\u306e\u4f8b\u3067\u306f\u3001<code>asyncpg<\/code>\u3092\u4f7f\u3063\u3066PostgreSQL\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306b\u975e\u540c\u671f\u30a2\u30af\u30bb\u30b9\u3057\u3066\u3044\u307e\u3059\u3002<code>main<\/code>\u95a2\u6570\u3067\u3001\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u63a5\u7d9a\u30d7\u30fc\u30eb\u3092\u4f5c\u6210\u3057\u3001<code>products<\/code>\u30c6\u30fc\u30d6\u30eb\u3092\u4f5c\u6210\u3057\u3066\u3044\u307e\u3059\u3002\u6b21\u306b\u3001\u65b0\u3057\u3044\u88fd\u54c1\u3092\u633f\u5165\u3057\u3001\u6700\u5f8c\u306b<code>products<\/code>\u30c6\u30fc\u30d6\u30eb\u304b\u3089\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3057\u3066\u8868\u793a\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-11\">WebSocket\u3092\u4f7f\u3063\u305f\u30ea\u30a2\u30eb\u30bf\u30a4\u30e0\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3<\/h3>\n\n\n\n<p><code>websockets<\/code>\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u4f7f\u7528\u3059\u308b\u3068\u3001WebSocket\u30b5\u30fc\u30d0\u30fc\u3068\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u3092\u7c21\u5358\u306b\u5b9f\u88c5\u3067\u304d\u307e\u3059\u3002<code>websockets.serve()<\/code>\u3092\u4f7f\u3063\u3066WebSocket\u30b5\u30fc\u30d0\u30fc\u3092\u8d77\u52d5\u3057\u3001<code>websockets.connect()<\/code>\u3092\u4f7f\u3063\u3066WebSocket\u30b5\u30fc\u30d0\u30fc\u306b\u63a5\u7d9a\u3057\u307e\u3059\u3002\u30e1\u30c3\u30bb\u30fc\u30b8\u306e\u9001\u53d7\u4fe1\u306f\u3001<code>await<\/code>\u3092\u4f7f\u3063\u3066\u975e\u540c\u671f\u306b\u884c\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9\uff08\u30b5\u30fc\u30d0\u30fc\u5074\uff09:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import asyncio\nimport websockets\n\nasync def echo(websocket, path):\n    async for message in websocket:\n        await websocket.send(f\"Server received: {message}\")\n\nstart_server = websockets.serve(echo, \"localhost\", 8765)\n\nasyncio.get_event_loop().run_until_complete(start_server)\nasyncio.get_event_loop().run_forever()<\/pre>\n\n\n\n<p>\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9\uff08\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u5074\uff09:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import asyncio\nimport websockets\n\nasync def send_messages():\n    async with websockets.connect(\"ws:\/\/localhost:8765\") as websocket:\n        for i in range(5):\n            message = f\"Message {i}\"\n            await websocket.send(message)\n            response = await websocket.recv()\n            print(response)\n\nasyncio.run(send_messages())<\/pre>\n\n\n\n<p>\u3053\u306e\u4f8b\u3067\u306f\u3001<code>websockets<\/code>\u3092\u4f7f\u3063\u3066\u30b7\u30f3\u30d7\u30eb\u306a\u30a8\u30b3\u30fc\u30b5\u30fc\u30d0\u30fc\u3092\u5b9f\u88c5\u3057\u3066\u3044\u307e\u3059\u3002\u30b5\u30fc\u30d0\u30fc\u5074\u3067\u306f\u3001\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u304b\u3089\u53d7\u4fe1\u3057\u305f\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u3001\u201dServer received: \u201c\u3068\u3044\u3046\u30d7\u30ec\u30d5\u30a3\u30c3\u30af\u30b9\u3092\u4ed8\u3051\u3066\u9001\u308a\u8fd4\u3057\u3066\u3044\u307e\u3059\u3002\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u5074\u3067\u306f\u30015\u3064\u306e\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u9806\u756a\u306b\u9001\u4fe1\u3057\u3001\u30b5\u30fc\u30d0\u30fc\u304b\u3089\u306e\u5fdc\u7b54\u3092\u8868\u793a\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u3053\u308c\u3089\u306e\u30b3\u30fc\u30c9\u4f8b\u306f\u3001asyncio\u3092\u4f7f\u3063\u305f\u5b9f\u8df5\u7684\u306a\u975e\u540c\u671f\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u306e\u4e00\u90e8\u3067\u3059\u3002\u4ed6\u306b\u3082\u3001\u975e\u540c\u671f\u30d5\u30a1\u30a4\u30ebI\/O\u3001\u975e\u540c\u671f\u30b5\u30d6\u30d7\u30ed\u30bb\u30b9\u306e\u5b9f\u884c\u306a\u3069\u3001\u69d8\u3005\u306a\u5834\u9762\u3067asyncio\u3092\u6d3b\u7528\u3067\u304d\u307e\u3059\u3002asyncio\u3092\u4f7f\u3044\u3053\u306a\u3059\u3053\u3068\u3067\u3001\u9ad8\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u3067\u52b9\u7387\u7684\u306a\u975e\u540c\u671f\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u958b\u767a\u3067\u304d\u308b\u3067\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"i-12\">asyncio\u306e\u30d9\u30b9\u30c8\u30d7\u30e9\u30af\u30c6\u30a3\u30b9\u3068Tips<\/h2>\n\n\n\n<p>asyncio\u3092\u4f7f\u3063\u3066\u52b9\u7387\u7684\u3067\u9ad8\u54c1\u8cea\u306a\u30b3\u30fc\u30c9\u3092\u66f8\u304f\u305f\u3081\u306b\u3001\u30d9\u30b9\u30c8\u30d7\u30e9\u30af\u30c6\u30a3\u30b9\u3068Tips\u3092\u7406\u89e3\u3057\u3066\u304a\u304f\u3053\u3068\u304c\u91cd\u8981\u3067\u3059\u3002\u3053\u3053\u3067\u306f\u3001\u4f8b\u5916\u51e6\u7406\u3068\u30a8\u30e9\u30fc\u30cf\u30f3\u30c9\u30ea\u30f3\u30b0\u3001\u30c7\u30d0\u30c3\u30b0\u3068\u30ed\u30b0\u51fa\u529b\u306e\u30c6\u30af\u30cb\u30c3\u30af\u3001\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u6539\u5584\u306e\u305f\u3081\u306e\u8a2d\u8a08\u3068\u5b9f\u88c5\u306b\u3064\u3044\u3066\u8aac\u660e\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-13\">\u4f8b\u5916\u51e6\u7406\u3068\u30a8\u30e9\u30fc\u30cf\u30f3\u30c9\u30ea\u30f3\u30b0<\/h3>\n\n\n\n<p>\u975e\u540c\u671f\u30b3\u30fc\u30c9\u3067\u306e\u4f8b\u5916\u51e6\u7406\u306b\u306f\u3001<code>try<\/code>\/<code>except<\/code>\u3092\u4f7f\u3044\u307e\u3059\u3002<code>asyncio.TimeoutError<\/code>\u3092\u4f7f\u3063\u3066\u30bf\u30a4\u30e0\u30a2\u30a6\u30c8\u30a8\u30e9\u30fc\u3092\u51e6\u7406\u3057\u3001<code>asyncio.CancelledError<\/code>\u3092\u4f7f\u3063\u3066\u30bf\u30b9\u30af\u306e\u30ad\u30e3\u30f3\u30bb\u30eb\u3092\u51e6\u7406\u3057\u307e\u3059\u3002<code>asyncio.shield()<\/code>\u3092\u4f7f\u3046\u3068\u3001\u30bf\u30b9\u30af\u306e\u30ad\u30e3\u30f3\u30bb\u30eb\u3092\u9632\u3050\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import asyncio\n\nasync def fetch_data(delay):\n    try:\n        await asyncio.sleep(delay)\n        return f\"Data fetched after {delay} seconds\"\n    except asyncio.CancelledError:\n        print(f\"Task cancelled after {delay} seconds\")\n        raise\n\nasync def main():\n    try:\n        task = asyncio.create_task(fetch_data(2))\n        result = await asyncio.wait_for(asyncio.shield(task), timeout=1)\n        print(result)\n    except asyncio.TimeoutError:\n        print(\"Task timed out\")\n        task.cancel()\n        await task\n\nasyncio.run(main())<\/pre>\n\n\n\n<p>\u3053\u306e\u4f8b\u3067\u306f\u3001<code>fetch_data<\/code>\u95a2\u6570\u3067\u6307\u5b9a\u3055\u308c\u305f\u79d2\u6570\u3060\u3051\u5f85\u6a5f\u3057\u3001\u30c7\u30fc\u30bf\u3092\u8fd4\u3057\u307e\u3059\u3002<code>main<\/code>\u95a2\u6570\u3067\u306f\u3001<code>fetch_data<\/code>\u95a2\u6570\u3092\u30bf\u30b9\u30af\u3068\u3057\u3066\u4f5c\u6210\u3057\u3001<code>asyncio.wait_for<\/code>\u3092\u4f7f\u3063\u30661\u79d2\u306e\u30bf\u30a4\u30e0\u30a2\u30a6\u30c8\u3092\u8a2d\u5b9a\u3057\u3066\u3044\u307e\u3059\u3002<code>asyncio.shield<\/code>\u3092\u4f7f\u3063\u3066\u30bf\u30b9\u30af\u3092\u30e9\u30c3\u30d7\u3059\u308b\u3053\u3068\u3067\u3001\u30bf\u30a4\u30e0\u30a2\u30a6\u30c8\u304c\u767a\u751f\u3057\u3066\u3082\u30bf\u30b9\u30af\u304c\u30ad\u30e3\u30f3\u30bb\u30eb\u3055\u308c\u306a\u3044\u3088\u3046\u306b\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-14\">\u30c7\u30d0\u30c3\u30b0\u3068\u30ed\u30b0\u51fa\u529b\u306e\u30c6\u30af\u30cb\u30c3\u30af<\/h3>\n\n\n\n<p><code>logging<\/code>\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u4f7f\u3063\u3066\u3001\u975e\u540c\u671f\u30b3\u30fc\u30c9\u306e\u30ed\u30b0\u3092\u51fa\u529b\u3067\u304d\u307e\u3059\u3002<code>asyncio.get_running_loop().set_debug(True)<\/code>\u3092\u4f7f\u3063\u3066\u30c7\u30d0\u30c3\u30b0\u30e2\u30fc\u30c9\u3092\u6709\u52b9\u5316\u3057\u3001<code>asyncio.get_running_loop().slow_callback_duration<\/code>\u3092\u8a2d\u5b9a\u3057\u3066\u3001\u9045\u3044\u30b3\u30fc\u30eb\u30d0\u30c3\u30af\u3092\u691c\u51fa\u3067\u304d\u307e\u3059\u3002<code>python -m asyncio<\/code>\u30b3\u30de\u30f3\u30c9\u3092\u4f7f\u3046\u3068\u3001\u30a4\u30d9\u30f3\u30c8\u30eb\u30fc\u30d7\u306e\u30c7\u30d0\u30c3\u30b0\u60c5\u5831\u3092\u51fa\u529b\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import asyncio\nimport logging\n\nlogging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(message)s', datefmt='%Y-%m-%d %H:%M:%S')\n\nasync def task1():\n    logging.debug(\"Task 1 started\")\n    await asyncio.sleep(1)\n    logging.debug(\"Task 1 finished\")\n\nasync def task2():\n    logging.debug(\"Task 2 started\")\n    await asyncio.sleep(2)\n    logging.debug(\"Task 2 finished\")\n\nasync def main():\n    asyncio.get_running_loop().set_debug(True)\n    asyncio.get_running_loop().slow_callback_duration = 0.5\n    await asyncio.gather(task1(), task2())\n\nasyncio.run(main(), debug=True)<\/pre>\n\n\n\n<p>\u3053\u306e\u4f8b\u3067\u306f\u3001<code>logging<\/code>\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u4f7f\u3063\u3066\u30c7\u30d0\u30c3\u30b0\u30ec\u30d9\u30eb\u306e\u30ed\u30b0\u3092\u51fa\u529b\u3057\u3066\u3044\u307e\u3059\u3002<code>asyncio.get_running_loop().set_debug(True)<\/code>\u3092\u4f7f\u3063\u3066\u30c7\u30d0\u30c3\u30b0\u30e2\u30fc\u30c9\u3092\u6709\u52b9\u5316\u3057\u3001<code>asyncio.get_running_loop().slow_callback_duration<\/code>\u30920.5\u79d2\u306b\u8a2d\u5b9a\u3057\u3066\u3001\u9045\u3044\u30b3\u30fc\u30eb\u30d0\u30c3\u30af\u3092\u691c\u51fa\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-15\">\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u6539\u5584\u306e\u305f\u3081\u306e\u8a2d\u8a08\u3068\u5b9f\u88c5<\/h3>\n\n\n\n<p>\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u3092\u6539\u5584\u3059\u308b\u305f\u3081\u306b\u3001I\/O bound\u30bf\u30b9\u30af\u3068CPU bound\u30bf\u30b9\u30af\u3092\u5206\u96e2\u3059\u308b\u3053\u3068\u304c\u91cd\u8981\u3067\u3059\u3002<code>asyncio.Queue<\/code>\u3092\u4f7f\u3063\u3066\u30bf\u30b9\u30af\u9593\u3067\u30c7\u30fc\u30bf\u3092\u5b89\u5168\u306b\u5171\u6709\u3057\u3001<code>asyncio.Semaphore<\/code>\u3092\u4f7f\u3063\u3066\u540c\u6642\u5b9f\u884c\u30bf\u30b9\u30af\u306e\u6570\u3092\u5236\u9650\u3067\u304d\u307e\u3059\u3002<code>asyncio.gather()<\/code>\u3092\u4f7f\u3046\u3068\u3001\u8907\u6570\u306e\u30bf\u30b9\u30af\u3092\u52b9\u7387\u7684\u306b\u5b9f\u884c\u3067\u304d\u307e\u3059\u3002\u307e\u305f\u3001<code>uvloop<\/code>\u306a\u3069\u306e\u9ad8\u901f\u306a\u30a4\u30d9\u30f3\u30c8\u30eb\u30fc\u30d7\u306e\u5b9f\u88c5\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u3067\u3001\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u3092\u5411\u4e0a\u3055\u305b\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import asyncio\nimport aiohttp\n\nasync def fetch(session, url):\n    async with session.get(url) as response:\n        return await response.text()\n\nasync def main():\n    async with aiohttp.ClientSession() as session:\n        urls = [f\"https:\/\/example.com\/api\/data\/{i}\" for i in range(100)]\n        queue = asyncio.Queue()\n\n        async def worker():\n            while True:\n                url = await queue.get()\n                data = await fetch(session, url)\n                print(f\"Fetched data from {url}: {len(data)}\")\n                queue.task_done()\n\n        workers = [asyncio.create_task(worker()) for _ in range(10)]\n\n        for url in urls:\n            await queue.put(url)\n\n        await queue.join()\n\n        for worker in workers:\n            worker.cancel()\n\nasyncio.run(main())<\/pre>\n\n\n\n<p>\u3053\u306e\u4f8b\u3067\u306f\u3001<code>aiohttp<\/code>\u3092\u4f7f\u3063\u3066\u8907\u6570\u306eURL\u304b\u3089\u30c7\u30fc\u30bf\u3092\u4e26\u884c\u3057\u3066\u53d6\u5f97\u3057\u3066\u3044\u307e\u3059\u3002<code>asyncio.Queue<\/code>\u3092\u4f7f\u3063\u3066URL\u3092\u30ef\u30fc\u30ab\u30fc\u30bf\u30b9\u30af\u306b\u5206\u914d\u3057\u3001<code>asyncio.create_task<\/code>\u3092\u4f7f\u3063\u306610\u500b\u306e\u30ef\u30fc\u30ab\u30fc\u30bf\u30b9\u30af\u3092\u4f5c\u6210\u3057\u3066\u3044\u307e\u3059\u3002\u5404\u30ef\u30fc\u30ab\u30fc\u30bf\u30b9\u30af\u306f\u3001\u30ad\u30e5\u30fc\u304b\u3089URL\u3092\u53d6\u5f97\u3057\u3001<code>fetch<\/code>\u95a2\u6570\u3092\u4f7f\u3063\u3066\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3057\u307e\u3059\u3002<code>queue.join()<\/code>\u3092\u4f7f\u3063\u3066\u3059\u3079\u3066\u306e\u30bf\u30b9\u30af\u304c\u5b8c\u4e86\u3059\u308b\u307e\u3067\u5f85\u6a5f\u3057\u3001\u6700\u5f8c\u306b\u30ef\u30fc\u30ab\u30fc\u30bf\u30b9\u30af\u3092\u30ad\u30e3\u30f3\u30bb\u30eb\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u3053\u308c\u3089\u306e\u30d9\u30b9\u30c8\u30d7\u30e9\u30af\u30c6\u30a3\u30b9\u3068Tips\u3092\u6d3b\u7528\u3059\u308b\u3053\u3068\u3067\u3001asyncio\u3092\u4f7f\u3063\u305f\u975e\u540c\u671f\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u3067\u3088\u308a\u52b9\u7387\u7684\u3067\u9ad8\u54c1\u8cea\u306a\u30b3\u30fc\u30c9\u3092\u66f8\u304f\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u9069\u5207\u306a\u4f8b\u5916\u51e6\u7406\u3068\u30a8\u30e9\u30fc\u30cf\u30f3\u30c9\u30ea\u30f3\u30b0\u3001\u30c7\u30d0\u30c3\u30b0\u3068\u30ed\u30b0\u51fa\u529b\u3001\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u6539\u5584\u306e\u305f\u3081\u306e\u8a2d\u8a08\u3068\u5b9f\u88c5\u3092\u5fc3\u304c\u3051\u308b\u3053\u3068\u304c\u91cd\u8981\u3067\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"i-16\">asyncio\u3092\u4f7f\u3063\u305f\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u958b\u767a\u4e8b\u4f8b<\/h2>\n\n\n\n<p>\u3053\u3053\u3067\u306f\u3001asyncio\u3092\u4f7f\u3063\u305f\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u958b\u767a\u306e\u5b9f\u8df5\u7684\u306a\u4e8b\u4f8b\u3092\u7d39\u4ecb\u3057\u307e\u3059\u3002\u9ad8\u30c8\u30e9\u30d5\u30a3\u30c3\u30af\u306b\u8010\u3048\u308bWeb\u30b5\u30fc\u30d0\u30fc\u306e\u69cb\u7bc9\u3001\u5927\u91cf\u306e\u30bf\u30b9\u30af\u3092\u52b9\u7387\u7684\u306b\u51e6\u7406\u3059\u308b\u30b8\u30e7\u30d6\u30ad\u30e5\u30fc\u3001\u30ea\u30a2\u30eb\u30bf\u30a4\u30e0\u6027\u304c\u6c42\u3081\u3089\u308c\u308b\u30c1\u30e3\u30c3\u30c8\u30a2\u30d7\u30ea\u306e\u958b\u767a\u306a\u3069\u306e\u4e8b\u4f8b\u3092\u901a\u3058\u3066\u3001asyncio\u306e\u6d3b\u7528\u65b9\u6cd5\u3092\u5b66\u3073\u307e\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-17\">\u9ad8\u30c8\u30e9\u30d5\u30a3\u30c3\u30af\u306b\u8010\u3048\u308bWeb\u30b5\u30fc\u30d0\u30fc\u306e\u69cb\u7bc9<\/h3>\n\n\n\n<p><code>aiohttp<\/code>\u3092\u4f7f\u3063\u3066\u3001\u975e\u540c\u671fWeb\u30b5\u30fc\u30d0\u30fc\u3092\u5b9f\u88c5\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<code>aiohttp.web<\/code>\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u4f7f\u3063\u3066\u30eb\u30fc\u30c6\u30a3\u30f3\u30b0\u3068\u30ea\u30af\u30a8\u30b9\u30c8\u30cf\u30f3\u30c9\u30ea\u30f3\u30b0\u3092\u5b9a\u7fa9\u3057\u3001<code>asyncio<\/code>\u3092\u4f7f\u3063\u3066\u975e\u540c\u671fI\/O\u3092\u6d3b\u7528\u3059\u308b\u3053\u3068\u3067\u3001\u9ad8\u3044\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u3092\u5b9f\u73fe\u3067\u304d\u307e\u3059\u3002\u3055\u3089\u306b\u3001<code>uvloop<\/code>\u3092\u4f7f\u3063\u3066\u30a4\u30d9\u30f3\u30c8\u30eb\u30fc\u30d7\u306e\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u3092\u5411\u4e0a\u3055\u305b\u308b\u3053\u3068\u3082\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">from aiohttp import web\n\nasync def handle(request):\n    name = request.match_info.get('name', \"Anonymous\")\n    text = f\"Hello, {name}\"\n    return web.Response(text=text)\n\nasync def health_check(request):\n    return web.Response(text=\"OK\")\n\napp = web.Application()\napp.add_routes([web.get('\/', handle),\n                web.get('\/{name}', handle),\n                web.get('\/health', health_check)])\n\nif __name__ == '__main__':\n    web.run_app(app, port=8080)<\/pre>\n\n\n\n<p>\u3053\u306e\u4f8b\u3067\u306f\u3001<code>aiohttp<\/code>\u3092\u4f7f\u3063\u3066\u7c21\u5358\u306aWeb\u30b5\u30fc\u30d0\u30fc\u3092\u5b9f\u88c5\u3057\u3066\u3044\u307e\u3059\u3002\u30eb\u30fc\u30c8\u30d1\u30b9\uff08<code>\/<\/code>\uff09\u3068\u30d1\u30e9\u30e1\u30fc\u30bf\u4ed8\u304d\u306e\u30d1\u30b9\uff08<code>\/{name}<\/code>\uff09\u306b\u5bfe\u3059\u308b\u30cf\u30f3\u30c9\u30e9\u3092\u5b9a\u7fa9\u3057\u3001<code>\/health<\/code>\u30d1\u30b9\u3067\u306f\u30d8\u30eb\u30b9\u30c1\u30a7\u30c3\u30af\u7528\u306e\u30a8\u30f3\u30c9\u30dd\u30a4\u30f3\u30c8\u3092\u63d0\u4f9b\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-18\">\u5927\u91cf\u306e\u30bf\u30b9\u30af\u3092\u52b9\u7387\u7684\u306b\u51e6\u7406\u3059\u308b\u30b8\u30e7\u30d6\u30ad\u30e5\u30fc<\/h3>\n\n\n\n<p><code>asyncio.Queue<\/code>\u3092\u4f7f\u3063\u3066\u3001\u975e\u540c\u671f\u30b8\u30e7\u30d6\u30ad\u30e5\u30fc\u3092\u5b9f\u88c5\u3067\u304d\u307e\u3059\u3002\u30d7\u30ed\u30c7\u30e5\u30fc\u30b5\u30fc\u30bf\u30b9\u30af\u3068\u30b3\u30f3\u30b7\u30e5\u30fc\u30de\u30fc\u30bf\u30b9\u30af\u3092\u5206\u96e2\u3057\u3001\u52b9\u7387\u7684\u306a\u51e6\u7406\u3092\u5b9f\u73fe\u3057\u307e\u3059\u3002<code>asyncio.Semaphore<\/code>\u3092\u4f7f\u3063\u3066\u540c\u6642\u5b9f\u884c\u30bf\u30b9\u30af\u306e\u6570\u3092\u5236\u9650\u3057\u3001\u30d0\u30c3\u30af\u30d7\u30ec\u30c3\u30b7\u30e3\u30fc\u3092\u9069\u5207\u306b\u51e6\u7406\u3059\u308b\u3053\u3068\u3067\u3001\u30e1\u30e2\u30ea\u4f7f\u7528\u91cf\u3092\u6291\u5236\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import asyncio\nimport random\n\nasync def producer(queue, n):\n    for i in range(n):\n        await asyncio.sleep(random.randint(1, 3))\n        item = f\"Task {i}\"\n        await queue.put(item)\n        print(f\"Produced {item}\")\n\nasync def consumer(queue, name, semaphore):\n    while True:\n        async with semaphore:\n            item = await queue.get()\n            print(f\"{name} processing {item}\")\n            await asyncio.sleep(random.randint(1, 3))\n            queue.task_done()\n\nasync def main():\n    queue = asyncio.Queue()\n    semaphore = asyncio.Semaphore(3)\n    producers = [asyncio.create_task(producer(queue, 10)) for _ in range(3)]\n    consumers = [asyncio.create_task(consumer(queue, f\"Worker {i}\", semaphore)) for i in range(5)]\n\n    await asyncio.gather(*producers)\n    await queue.join()\n\n    for c in consumers:\n        c.cancel()\n\nasyncio.run(main())<\/pre>\n\n\n\n<p>\u3053\u306e\u4f8b\u3067\u306f\u3001\u30d7\u30ed\u30c7\u30e5\u30fc\u30b5\u30fc\u30bf\u30b9\u30af\u304c\u30b8\u30e7\u30d6\u3092\u30ad\u30e5\u30fc\u306b\u8ffd\u52a0\u3057\u3001\u30b3\u30f3\u30b7\u30e5\u30fc\u30de\u30fc\u30bf\u30b9\u30af\u304c\u30b8\u30e7\u30d6\u3092\u51e6\u7406\u3057\u307e\u3059\u3002<code>asyncio.Semaphore<\/code>\u3092\u4f7f\u3063\u3066\u3001\u540c\u6642\u306b\u51e6\u7406\u3067\u304d\u308b\u30b8\u30e7\u30d6\u306e\u6570\u30923\u306b\u5236\u9650\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-19\">\u30ea\u30a2\u30eb\u30bf\u30a4\u30e0\u6027\u304c\u6c42\u3081\u3089\u308c\u308b\u30c1\u30e3\u30c3\u30c8\u30a2\u30d7\u30ea\u306e\u958b\u767a<\/h3>\n\n\n\n<p><code>websockets<\/code>\u3092\u4f7f\u3063\u3066\u3001\u975e\u540c\u671fWebSocket\u30b5\u30fc\u30d0\u30fc\u3092\u5b9f\u88c5\u3067\u304d\u307e\u3059\u3002\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u304b\u3089\u306e\u63a5\u7d9a\u3092\u53d7\u3051\u5165\u308c\u3001\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u30d6\u30ed\u30fc\u30c9\u30ad\u30e3\u30b9\u30c8\u3057\u307e\u3059\u3002<code>asyncio.Queue<\/code>\u3092\u4f7f\u3063\u3066\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u52b9\u7387\u7684\u306b\u914d\u4fe1\u3057\u3001\u63a5\u7d9a\u7ba1\u7406\u3068\u30a8\u30e9\u30fc\u30cf\u30f3\u30c9\u30ea\u30f3\u30b0\u3092\u9069\u5207\u306b\u884c\u3046\u3053\u3068\u3067\u3001\u5b89\u5b9a\u3057\u305f\u30b5\u30fc\u30d3\u30b9\u3092\u63d0\u4f9b\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import asyncio\nimport websockets\nimport json\n\nconnected = set()\nmessage_queue = asyncio.Queue()\n\nasync def handler(websocket, path):\n    connected.add(websocket)\n    try:\n        async for message in websocket:\n            await message_queue.put(message)\n    finally:\n        connected.remove(websocket)\n\nasync def broadcast():\n    while True:\n        message = await message_queue.get()\n        for conn in connected:\n            try:\n                await conn.send(message)\n            except websockets.ConnectionClosed:\n                pass\n        message_queue.task_done()\n\nasync def main():\n    async with websockets.serve(handler, \"localhost\", 8765):\n        await broadcast()\n\nasyncio.run(main())<\/pre>\n\n\n\n<p>\u3053\u306e\u4f8b\u3067\u306f\u3001<code>websockets<\/code>\u3092\u4f7f\u3063\u3066WebSocket\u30b5\u30fc\u30d0\u30fc\u3092\u5b9f\u88c5\u3057\u3066\u3044\u307e\u3059\u3002<code>connected<\/code>\u30bb\u30c3\u30c8\u306b\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u306e\u63a5\u7d9a\u3092\u4fdd\u5b58\u3057\u3001<code>message_queue<\/code>\u3092\u4f7f\u3063\u3066\u53d7\u4fe1\u3057\u305f\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u4fdd\u6301\u3057\u307e\u3059\u3002<code>handler<\/code>\u95a2\u6570\u3067\u306f\u3001\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u304b\u3089\u306e\u30e1\u30c3\u30bb\u30fc\u30b8\u3092<code>message_queue<\/code>\u306b\u8ffd\u52a0\u3057\u307e\u3059\u3002<code>broadcast<\/code>\u95a2\u6570\u3067\u306f\u3001<code>message_queue<\/code>\u304b\u3089\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u53d6\u308a\u51fa\u3057\u3001\u63a5\u7d9a\u4e2d\u306e\u5168\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u306b\u30d6\u30ed\u30fc\u30c9\u30ad\u30e3\u30b9\u30c8\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u3053\u308c\u3089\u306e\u4e8b\u4f8b\u306f\u3001asyncio\u3092\u4f7f\u3063\u305f\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u958b\u767a\u306e\u4e00\u90e8\u3067\u3059\u3002\u4ed6\u306b\u3082\u3001\u975e\u540c\u671f\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u30a2\u30af\u30bb\u30b9\u3001\u975e\u540c\u671f\u30d5\u30a1\u30a4\u30ebI\/O\u3001\u975e\u540c\u671fAPI\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u306e\u958b\u767a\u306a\u3069\u3001\u69d8\u3005\u306a\u5834\u9762\u3067asyncio\u3092\u6d3b\u7528\u3067\u304d\u307e\u3059\u3002asyncio\u306e\u7279\u6027\u3092\u7406\u89e3\u3057\u3001\u9069\u5207\u306b\u8a2d\u8a08\u30fb\u5b9f\u88c5\u3059\u308b\u3053\u3068\u3067\u3001\u9ad8\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u3067\u52b9\u7387\u7684\u306a\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u958b\u767a\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3067\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"i-20\">asyncio\u306e\u5b66\u7fd2\u30ea\u30bd\u30fc\u30b9\u3068\u53c2\u8003\u60c5\u5831<\/h2>\n\n\n\n<p>asyncio\u3092\u5b66\u3073\u3001\u975e\u540c\u671f\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u306e\u30b9\u30ad\u30eb\u3092\u5411\u4e0a\u3055\u305b\u308b\u305f\u3081\u306b\u3001\u69d8\u3005\u306a\u5b66\u7fd2\u30ea\u30bd\u30fc\u30b9\u3092\u6d3b\u7528\u3059\u308b\u3053\u3068\u304c\u91cd\u8981\u3067\u3059\u3002\u3053\u3053\u3067\u306f\u3001\u516c\u5f0f\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u3068\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u3001\u304a\u3059\u3059\u3081\u306e\u66f8\u7c4d\u3068\u52d5\u753b\u8b1b\u5ea7\u3001\u7d99\u7d9a\u7684\u306a\u5b66\u7fd2\u65b9\u6cd5\u306b\u3064\u3044\u3066\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-21\">\u516c\u5f0f\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u3068\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb<\/h3>\n\n\n\n<p>Python\u516c\u5f0f\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u306easyncio\u30bb\u30af\u30b7\u30e7\u30f3\uff08<a href=\"https:\/\/docs.python.org\/3\/library\/asyncio.html\">https:\/\/docs.python.org\/3\/library\/asyncio.html<\/a>\uff09\u306f\u3001asyncio\u306e\u57fa\u672c\u7684\u306a\u4f7f\u3044\u65b9\u3084API\u30ea\u30d5\u30a1\u30ec\u30f3\u30b9\u304c\u7db2\u7f85\u3055\u308c\u3066\u3044\u308b\u6700\u3082\u91cd\u8981\u306a\u30ea\u30bd\u30fc\u30b9\u3067\u3059\u3002\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u3084\u9ad8\u5ea6\u306a\u30c8\u30d4\u30c3\u30af\u3082\u63d0\u4f9b\u3055\u308c\u3066\u3044\u308b\u305f\u3081\u3001\u521d\u5fc3\u8005\u304b\u3089\u4e0a\u7d1a\u8005\u307e\u3067\u5e45\u5e83\u304f\u6d3b\u7528\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u307e\u305f\u3001Real Python\u306e\u201dAsync IO in Python: A Complete Walkthrough\u201d\uff08<a href=\"https:\/\/realpython.com\/async-io-python\/\">https:\/\/realpython.com\/async-io-python\/<\/a>\uff09\u306f\u3001asyncio\u306e\u57fa\u790e\u304b\u3089\u5fdc\u7528\u307e\u3067\u3092\u8a73\u7d30\u306b\u89e3\u8aac\u3057\u305f\u512a\u308c\u305f\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u3067\u3059\u3002\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9\u3068\u4e01\u5be7\u306a\u8aac\u660e\u3067\u3001asyncio\u306e\u7406\u89e3\u3092\u6df1\u3081\u3089\u308c\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-22\">\u304a\u3059\u3059\u3081\u306e\u66f8\u7c4d<\/h3>\n\n\n\n<p>asyncio\u3092\u4f53\u7cfb\u7684\u306b\u5b66\u3076\u305f\u3081\u306b\u306f\u3001\u66f8\u7c4d\u3084\u52d5\u753b\u8b1b\u5ea7\u3092\u6d3b\u7528\u3059\u308b\u306e\u304c\u52b9\u679c\u7684\u3067\u3059\u3002\u4ee5\u4e0b\u306e\u66f8\u7c4d\u306f\u3001asyncio\u3092\u4f7f\u3063\u305f\u4e26\u884c\u51e6\u7406\u3068\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u3092\u8a73\u3057\u304f\u89e3\u8aac\u3057\u3066\u304a\u308a\u3001\u5b9f\u8df5\u7684\u306a\u4f8b\u984c\u3084\u30d9\u30b9\u30c8\u30d7\u30e9\u30af\u30c6\u30a3\u30b9\u3082\u63d0\u4f9b\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u201cUsing Asyncio in Python\u201d by Caleb Hattingh (O\u2019Reilly Media)<\/li>\n\n\n\n<li>URL: <a href=\"https:\/\/www.oreilly.com\/library\/view\/using-asyncio-in\/9781492075325\/\">https:\/\/www.oreilly.com\/library\/view\/using-asyncio-in\/9781492075325\/<\/a><\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-23\">asyncio\u3092\u4f7f\u3044\u3053\u306a\u3059\u305f\u3081\u306e\u7d99\u7d9a\u7684\u306a\u5b66\u7fd2\u65b9\u6cd5<\/h3>\n\n\n\n<p>asyncio\u3092\u4f7f\u3044\u3053\u306a\u3059\u305f\u3081\u306b\u306f\u3001\u7d99\u7d9a\u7684\u306a\u5b66\u7fd2\u304c\u6b20\u304b\u305b\u307e\u305b\u3093\u3002\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u65b9\u6cd5\u3067\u3001\u6700\u65b0\u306e\u60c5\u5831\u3092\u8ffd\u8de1\u3057\u3001\u30b9\u30ad\u30eb\u3092\u5411\u4e0a\u3055\u305b\u307e\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u516c\u5f0f\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u3068PEP\u3092\u5b9a\u671f\u7684\u306b\u30c1\u30a7\u30c3\u30af\u3057\u3001\u6700\u65b0\u306e\u60c5\u5831\u3092\u8ffd\u8de1\u3059\u308b<\/li>\n<\/ol>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u30aa\u30fc\u30d7\u30f3\u30bd\u30fc\u30b9\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306e\u30b3\u30fc\u30c9\u30ea\u30fc\u30c7\u30a3\u30f3\u30b0\n<ul class=\"wp-block-list\">\n<li>asyncio\u3092\u4f7f\u3063\u305f\u5b9f\u969b\u306e\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306e\u30b3\u30fc\u30c9\u3092\u8aad\u3093\u3067\u3001\u5b9f\u8df5\u7684\u306a\u4f7f\u3044\u65b9\u3092\u5b66\u3076<\/li>\n\n\n\n<li>\u4f8b: Sanic (\u9ad8\u901f\u306aasyncio Web\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af) <a href=\"https:\/\/github.com\/sanic-org\/sanic\">https:\/\/github.com\/sanic-org\/sanic<\/a><\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>\u30b3\u30df\u30e5\u30cb\u30c6\u30a3\u3067\u306e\u60c5\u5831\u4ea4\u63db\u3068\u8cea\u554f\n<ul class=\"wp-block-list\">\n<li>Python\u95a2\u9023\u306e\u30d5\u30a9\u30fc\u30e9\u30e0\u3084Q&amp;A\u30b5\u30a4\u30c8\u3067\u3001asyncio\u306b\u95a2\u3059\u308b\u8b70\u8ad6\u306b\u53c2\u52a0\u3059\u308b<\/li>\n\n\n\n<li>\u4f8b: Stack Overflow\u3001Reddit r\/Python\u306a\u3069<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<p>\u3053\u308c\u3089\u306e\u5b66\u7fd2\u30ea\u30bd\u30fc\u30b9\u3092\u6d3b\u7528\u3057\u3001\u7d99\u7d9a\u7684\u306b\u5b66\u7fd2\u3059\u308b\u3053\u3068\u3067\u3001asyncio\u3092\u4f7f\u3044\u3053\u306a\u3059\u305f\u3081\u306e\u77e5\u8b58\u3068\u30b9\u30ad\u30eb\u3092\u8eab\u306b\u3064\u3051\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u5b9f\u969b\u306e\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3067asyncio\u3092\u6d3b\u7528\u3057\u306a\u304c\u3089\u3001\u30b3\u30df\u30e5\u30cb\u30c6\u30a3\u3067\u306e\u60c5\u5831\u4ea4\u63db\u3092\u901a\u3058\u3066\u3001\u975e\u540c\u671f\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u306e\u30a8\u30ad\u30b9\u30d1\u30fc\u30c8\u3092\u76ee\u6307\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"i-24\">\u307e\u3068\u3081\uff1aasyncio\u30de\u30b9\u30bf\u30fc\u306b\u306a\u308b\u305f\u3081\u306b<\/h2>\n\n\n\n<p>asyncio\u3092\u5b66\u3073\u3001\u975e\u540c\u671f\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u306e\u30b9\u30ad\u30eb\u3092\u8eab\u306b\u3064\u3051\u308b\u3053\u3068\u306f\u3001\u73fe\u4ee3\u306e\u30bd\u30d5\u30c8\u30a6\u30a7\u30a2\u958b\u767a\u306b\u304a\u3044\u3066\u975e\u5e38\u306b\u91cd\u8981\u3067\u3059\u3002\u3053\u3053\u3067\u306f\u3001asyncio\u3092\u5b66\u3076\u610f\u7fa9\u3068\u5c06\u6765\u6027\u3001\u975e\u540c\u671f\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u30b9\u30ad\u30eb\u304c\u6d3b\u304b\u305b\u308b\u9818\u57df\u3068\u4ed5\u4e8b\u3001\u305d\u3057\u3066asyncio\u30de\u30b9\u30bf\u30fc\u3078\u306e\u9053\u306e\u308a\u306b\u3064\u3044\u3066\u307e\u3068\u3081\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-25\">asyncio\u3092\u5b66\u3076\u610f\u7fa9\u3068\u5c06\u6765\u6027<\/h3>\n\n\n\n<p>\u975e\u540c\u671f\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u306e\u30b9\u30ad\u30eb\u306f\u3001Web\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3001API\u30b5\u30fc\u30d0\u30fc\u3001\u30c7\u30fc\u30bf\u51e6\u7406\u30d1\u30a4\u30d7\u30e9\u30a4\u30f3\u306a\u3069\u3001\u5e45\u5e83\u3044\u5206\u91ce\u3067\u5fc5\u8981\u3068\u3055\u308c\u3066\u3044\u307e\u3059\u3002\u30de\u30a4\u30af\u30ed\u30b5\u30fc\u30d3\u30b9\u30a2\u30fc\u30ad\u30c6\u30af\u30c1\u30e3\u3084\u30b5\u30fc\u30d0\u30fc\u30ec\u30b9\u30b3\u30f3\u30d4\u30e5\u30fc\u30c6\u30a3\u30f3\u30b0\u306b\u304a\u3044\u3066\u3082\u3001\u975e\u540c\u671f\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u306f\u91cd\u8981\u306a\u5f79\u5272\u3092\u679c\u305f\u3057\u307e\u3059\u3002Python\u4ee5\u5916\u306e\u8a00\u8a9e\u3067\u3082\u3001\u975e\u540c\u671f\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u306e\u6982\u5ff5\u306f\u5171\u901a\u3057\u3066\u3044\u308b\u305f\u3081\u3001\u7fd2\u5f97\u3057\u305f\u30b9\u30ad\u30eb\u306f\u4ed6\u306e\u8a00\u8a9e\u3084\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u306b\u3082\u5fdc\u7528\u3067\u304d\u307e\u3059\u3002\u975e\u540c\u671f\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u306e\u30b9\u30ad\u30eb\u3092\u8eab\u306b\u3064\u3051\u308b\u3053\u3068\u306f\u3001\u30ad\u30e3\u30ea\u30a2\u30a2\u30c3\u30d7\u306b\u3082\u5f79\u7acb\u3064\u3067\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-26\">\u975e\u540c\u671f\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u30b9\u30ad\u30eb\u304c\u6d3b\u304b\u305b\u308b\u9818\u57df\u3068\u4ed5\u4e8b<\/h3>\n\n\n\n<p>\u975e\u540c\u671f\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u30b9\u30ad\u30eb\u306f\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u9818\u57df\u3084\u4ed5\u4e8b\u3067\u6d3b\u304b\u3059\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>FastAPI\u3001Sanic\u3001Tornado\u306a\u3069\u306e\u975e\u540c\u671fWeb\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u3092\u4f7f\u3063\u305f\u958b\u767a<\/li>\n\n\n\n<li>\u9ad8\u6027\u80fd\u306a\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u30b5\u30fc\u30d0\u30fc\u3084API\u306e\u5b9f\u88c5<\/li>\n\n\n\n<li>\u30c1\u30e3\u30c3\u30c8\u3084\u30b2\u30fc\u30e0\u306a\u3069\u3001\u30ea\u30a2\u30eb\u30bf\u30a4\u30e0\u901a\u4fe1\u3092\u5fc5\u8981\u3068\u3059\u308b\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u958b\u767a<\/li>\n\n\n\n<li>\u5927\u91cf\u306e\u30c7\u30fc\u30bf\u51e6\u7406\u3084\u5206\u6563\u30b7\u30b9\u30c6\u30e0\u306e\u69cb\u7bc9<\/li>\n\n\n\n<li>\u30af\u30e9\u30a6\u30c9\u30b5\u30fc\u30d3\u30b9\u3084\u30b5\u30fc\u30d0\u30fc\u30ec\u30b9\u30a2\u30fc\u30ad\u30c6\u30af\u30c1\u30e3\u3092\u6d3b\u7528\u3057\u305f\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u958b\u767a<\/li>\n<\/ul>\n\n\n\n<p>\u3053\u308c\u3089\u306e\u9818\u57df\u3067\u306f\u3001\u975e\u540c\u671f\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u306e\u77e5\u8b58\u3068\u7d4c\u9a13\u304c\u6c42\u3081\u3089\u308c\u307e\u3059\u3002asyncio\u3092\u5b66\u3076\u3053\u3068\u3067\u3001\u3053\u308c\u3089\u306e\u4ed5\u4e8b\u3067\u6d3b\u8e8d\u3067\u304d\u308b\u53ef\u80fd\u6027\u304c\u5e83\u304c\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-27\">asyncio\u30de\u30b9\u30bf\u30fc\u3078\u306e\u9053\u306e\u308a\uff1a\u7d99\u7d9a\u7684\u306a\u5b66\u7fd2\u3068\u5b9f\u8df5\u306e\u91cd\u8981\u6027<\/h3>\n\n\n\n<p>asyncio\u30de\u30b9\u30bf\u30fc\u306b\u306a\u308b\u305f\u3081\u306b\u306f\u3001\u7d99\u7d9a\u7684\u306a\u5b66\u7fd2\u3068\u5b9f\u8df5\u304c\u6b20\u304b\u305b\u307e\u305b\u3093\u3002\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u884c\u52d5\u3092\u901a\u3058\u3066\u3001\u30b9\u30ad\u30eb\u3092\u5411\u4e0a\u3055\u305b\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>asyncio\u306e\u57fa\u790e\u3092\u3057\u3063\u304b\u308a\u3068\u8eab\u306b\u3064\u3051\u308b<\/li>\n\n\n\n<li>\u5b9f\u969b\u306e\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3084\u30aa\u30fc\u30d7\u30f3\u30bd\u30fc\u30b9\u3078\u306e\u53c2\u52a0\u3067\u5b9f\u8df5\u7d4c\u9a13\u3092\u7a4d\u3080<\/li>\n\n\n\n<li>\u65b0\u3057\u3044\u30e9\u30a4\u30d6\u30e9\u30ea\u3084\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u306b\u89e6\u308c\u3001\u77e5\u898b\u3092\u5e83\u3052\u308b<\/li>\n\n\n\n<li>\u30b3\u30df\u30e5\u30cb\u30c6\u30a3\u3067\u306e\u4ea4\u6d41\u3092\u901a\u3058\u3066\u3001\u30d9\u30b9\u30c8\u30d7\u30e9\u30af\u30c6\u30a3\u30b9\u3084\u6700\u65b0\u60c5\u5831\u3092\u5b66\u3076<\/li>\n\n\n\n<li>\u81ea\u5206\u306e\u7d4c\u9a13\u3084\u77e5\u8b58\u3092\u5171\u6709\u3057\u3001\u4ed6\u306e\u958b\u767a\u8005\u306e\u6210\u9577\u306b\u8ca2\u732e\u3059\u308b<\/li>\n<\/ol>\n\n\n\n<p>\u7d99\u7d9a\u7684\u306a\u5b66\u7fd2\u3068\u5b9f\u8df5\u3092\u901a\u3058\u3066\u3001asyncio\u3092\u4f7f\u3044\u3053\u306a\u3059\u30b9\u30ad\u30eb\u3092\u78e8\u3044\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002\u30b3\u30df\u30e5\u30cb\u30c6\u30a3\u3078\u306e\u53c2\u52a0\u3068\u8ca2\u732e\u3082\u3001\u81ea\u5206\u306e\u6210\u9577\u306b\u5f79\u7acb\u3064\u3060\u3051\u3067\u306a\u304f\u3001\u4ed6\u306e\u958b\u767a\u8005\u306e\u6210\u9577\u306b\u3082\u5bc4\u4e0e\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p>asyncio\u30de\u30b9\u30bf\u30fc\u3078\u306e\u9053\u306e\u308a\u306f\u3001\u4e00\u671d\u4e00\u5915\u3067\u9054\u6210\u3067\u304d\u308b\u3082\u306e\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3002\u3057\u304b\u3057\u3001\u65e5\u3005\u306e\u5b66\u7fd2\u3068\u5b9f\u8df5\u306e\u7a4d\u307f\u91cd\u306d\u304c\u3001\u3042\u306a\u305f\u3092\u975e\u540c\u671f\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u306e\u30a8\u30ad\u30b9\u30d1\u30fc\u30c8\u3078\u3068\u5c0e\u3044\u3066\u304f\u308c\u308b\u3067\u3057\u3087\u3046\u3002asyncio\u3092\u6df1\u304f\u7406\u89e3\u3057\u3001\u52b9\u679c\u7684\u306b\u6d3b\u7528\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308b\u3053\u3068\u3067\u3001\u3088\u308a\u9ad8\u5ea6\u306a\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u958b\u767a\u3057\u3001\u30ad\u30e3\u30ea\u30a2\u306e\u53ef\u80fd\u6027\u3092\u5e83\u3052\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u305d\u308c\u3067\u306f\u3001asyncio\u30de\u30b9\u30bf\u30fc\u3092\u76ee\u6307\u3057\u3066\u3001\u5b66\u7fd2\u3068\u5b9f\u8df5\u3092\u59cb\u3081\u307e\u3057\u3087\u3046\u3002\u3053\u306e\u8a18\u4e8b\u3067\u7d39\u4ecb\u3057\u305f\u77e5\u8b58\u3068\u30ea\u30bd\u30fc\u30b9\u3092\u6d3b\u7528\u3057\u3001\u975e\u540c\u671f\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u306e\u4e16\u754c\u3092\u63a2\u6c42\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u3042\u306a\u305f\u306e\u6210\u9577\u3068\u6d3b\u8e8d\u3092\u5fc3\u304b\u3089\u5fdc\u63f4\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python\u306e\u975e\u540c\u671f\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u30e9\u30a4\u30d6\u30e9\u30ea\u300casyncio\u300d\u306f\u3001\u9ad8\u6027\u80fd\u306a\u4e26\u884c\u51e6\u7406\u3092\u5b9f\u73fe\u3059\u308b\u305f\u3081\u306e\u5f37\u529b\u306a\u30c4\u30fc\u30eb\u3067\u3059\u3002\u3057\u304b\u3057\u3001asyncio\u3092\u52b9\u679c\u7684\u306b\u4f7f\u3044\u3053\u306a\u3059\u306b\u306f\u3001\u975e\u540c\u671f\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u306e\u6982\u5ff5\u3084\u7279\u6027\u3092\u7406\u89e3\u3057\u3001\u9069\u5207\u306a\u8a2d\u8a08\u3068\u5b9f &#8230; <\/p>\n","protected":false},"author":1,"featured_media":765,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":{"0":"post-764","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-python"},"_links":{"self":[{"href":"https:\/\/chocottopro.com\/index.php?rest_route=\/wp\/v2\/posts\/764","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/chocottopro.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/chocottopro.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/chocottopro.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/chocottopro.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=764"}],"version-history":[{"count":1,"href":"https:\/\/chocottopro.com\/index.php?rest_route=\/wp\/v2\/posts\/764\/revisions"}],"predecessor-version":[{"id":766,"href":"https:\/\/chocottopro.com\/index.php?rest_route=\/wp\/v2\/posts\/764\/revisions\/766"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/chocottopro.com\/index.php?rest_route=\/wp\/v2\/media\/765"}],"wp:attachment":[{"href":"https:\/\/chocottopro.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=764"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/chocottopro.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=764"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/chocottopro.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=764"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}