{"id":299703,"date":"2020-03-05T09:00:27","date_gmt":"2020-03-05T09:00:27","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=299703"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=299703","title":{"rendered":"Trio \u2013 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0434\u043b\u044f \u043b\u044e\u0434\u0435\u0439"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/company\/barsgroup\/blog\/490872\/\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/m7\/0o\/ye\/m70oyejwkcwdk32csx1mq2wprao.jpeg\" alt=\"image\"><\/p>\n<p>  \u0412 Python \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 <a href=\"https:\/\/github.com\/python-trio\/trio\">Trio <\/a>\u2013 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f.<br \/>  \u0417\u043d\u0430\u043a\u043e\u043c\u0441\u0442\u0432\u043e \u0441 Trio \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c \u0431\u0443\u0434\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u0442\u0435\u043c, \u043a\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043d\u0430 Asyncio, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u044d\u0442\u043e \u0445\u043e\u0440\u043e\u0448\u0430\u044f \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u0430, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0430\u044f \u0440\u0435\u0448\u0430\u0442\u044c \u0447\u0430\u0441\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c, \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c\u0441\u044f Asyncio. \u0412 \u044d\u0442\u043e\u043c \u043e\u0431\u0437\u043e\u0440\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u0447\u0442\u043e \u0438\u0437 \u0441\u0435\u0431\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 Trio \u0438 \u043a\u0430\u043a\u0438\u0435 \u0444\u0438\u0447\u0438 \u043e\u043d\u0430 \u043d\u0430\u043c \u0434\u0430\u0435\u0442. <br \/>  <a name=\"habracut\"><\/a><br \/>  \u0414\u043b\u044f \u0442\u0435\u0445, \u043a\u0442\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0443 \u0432 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u043c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438, \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0443\u044e \u0432\u0432\u043e\u0434\u043d\u0443\u044e \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0441\u0442\u044c \u0438 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0441\u0442\u044c. <\/p>\n<h3>\u0421\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0441\u0442\u044c \u0438 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0441\u0442\u044c <\/h3>\n<p>  \u0412 <b>\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u043c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438<\/b> \u0432\u0441\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u0438 \u043a \u043d\u043e\u0432\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439. \u041e\u0434\u043d\u0430\u043a\u043e \u043e\u0434\u043d\u0430 \u0438\u0437 \u0435\u0433\u043e \u00ab\u0431\u043e\u043b\u0435\u0432\u044b\u0445\u00bb \u0442\u043e\u0447\u0435\u043a \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e, \u0435\u0441\u043b\u0438 \u043e\u0434\u0438\u043d \u0438\u0437 \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043d\u0430\u0434 \u0437\u0430\u0434\u0430\u0447\u0435\u0439 \u043e\u0447\u0435\u043d\u044c \u0434\u043e\u043b\u0433\u043e, \u043c\u043e\u0436\u0435\u0442 \u0437\u0430\u0432\u0438\u0441\u043d\u0443\u0442\u044c \u0432\u0441\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430. \u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u0437\u0430\u0434\u0430\u0447\u0438, \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u044e\u0449\u0438\u0435 \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043c\u043e\u0449\u043d\u043e\u0441\u0442\u0435\u0439, \u043d\u043e \u0437\u0430\u043d\u0438\u043c\u0430\u044e\u0449\u0438\u0435 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u0440\u0430\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e, \u043e\u0442\u0434\u0430\u0432 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0434\u0440\u0443\u0433\u043e\u043c\u0443 \u043f\u043e\u0442\u043e\u043a\u0443. \u0412 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u043c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u043d\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043f\u0440\u0438\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0442\u0435\u043a\u0443\u0449\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u0443, \u0447\u0442\u043e\u0431\u044b \u0432 \u0435\u0435 \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043a\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e. <\/p>\n<p>  \u0414\u043b\u044f \u0447\u0435\u0433\u043e \u043d\u0443\u0436\u043d\u0430 <b>\u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0441\u0442\u044c<\/b>? \u041d\u0443\u0436\u043d\u043e \u0440\u0430\u0437\u043b\u0438\u0447\u0430\u0442\u044c \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0443\u044e \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0441\u0442\u044c \u0438 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0441\u0442\u044c \u0432\u0432\u043e\u0434\u0430-\u0432\u044b\u0432\u043e\u0434\u0430. \u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0440\u0435\u0447\u044c \u0438\u0434\u0435\u0442 \u0438\u043c\u0435\u043d\u043d\u043e \u043e\u0431 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0441\u0442\u0438 \u0432\u0432\u043e\u0434\u0430-\u0432\u044b\u0432\u043e\u0434\u0430. \u0413\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e \u2014 \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u044d\u043a\u043e\u043d\u043e\u043c\u0438\u0442\u044c \u0432\u0440\u0435\u043c\u044f \u0438 \u0431\u043e\u043b\u0435\u0435 \u0440\u0430\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u043c\u043e\u0449\u043d\u043e\u0441\u0442\u0438. \u0410\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u0431\u043e\u0439\u0442\u0438 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043d\u044b\u0435 \u043c\u0435\u0441\u0442\u0430 \u043f\u043e\u0442\u043e\u043a\u043e\u0432. \u0412 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0441\u0442\u0438 \u0432\u0432\u043e\u0434\u0430-\u0432\u044b\u0432\u043e\u0434\u0430 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u043f\u043e\u0442\u043e\u043a \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0436\u0434\u0430\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043a\u0430\u043a\u043e\u0433\u043e-\u0442\u043e \u0432\u043d\u0435\u0448\u043d\u0435\u0433\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u044f, \u0430 \u043e\u0442\u0434\u0430\u0441\u0442 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0434\u0440\u0443\u0433\u043e\u043c\u0443 \u043f\u043e\u0442\u043e\u043a\u0443. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043f\u043e \u0444\u0430\u043a\u0442\u0443, \u043e\u0434\u043d\u043e\u043c\u043e\u043c\u0435\u043d\u0442\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u043f\u043e\u0442\u043e\u043a. \u041e\u0442\u0434\u0430\u0432\u0448\u0438\u0439 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u043e\u0442\u043e\u043a \u0443\u0445\u043e\u0434\u0438\u0442 \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0438 \u0436\u0434\u0435\u0442, \u043a\u043e\u0433\u0434\u0430 \u0435\u043c\u0443 \u0432\u0435\u0440\u043d\u0435\u0442\u0441\u044f \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435. \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u043a \u0442\u043e\u043c\u0443 \u043c\u043e\u043c\u0435\u043d\u0442\u0443 \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0434\u0435\u0442 \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u043e\u0435 \u0432\u043d\u0435\u0448\u043d\u0435\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u0438 \u043c\u043e\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443. \u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0430\u0442\u044c\u0441\u044f \u043c\u0435\u0436\u0434\u0443 \u0437\u0430\u0434\u0430\u0447\u0430\u043c\u0438 \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043c\u0438\u043d\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0442\u0440\u0430\u0442\u0443 \u0432\u0440\u0435\u043c\u0435\u043d\u0438.<\/p>\n<p>  \u0418 \u0432\u043e\u0442 \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u043d\u043e\u0432\u0430 \u0432\u0435\u0440\u043d\u0443\u0442\u044c\u0441\u044f \u043a \u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 <b>Asyncio<\/b>. \u0412 \u043e\u0441\u043d\u043e\u0432\u0435 \u0440\u0430\u0431\u043e\u0442\u044b \u044d\u0442\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 <b>\u0446\u0438\u043a\u043b \u0441\u043e\u0431\u044b\u0442\u0438\u0439<\/b> (event loop), \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0432 \u0441\u0435\u0431\u044f \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0437\u0430\u0434\u0430\u0447 \u0438 \u0441\u0430\u043c \u0446\u0438\u043a\u043b. \u0426\u0438\u043a\u043b \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435\u043c \u0437\u0430\u0434\u0430\u0447, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e \u0432\u044b\u0442\u044f\u0433\u0438\u0432\u0430\u0435\u0442 \u0437\u0430\u0434\u0430\u0447\u0438 \u0438\u0437 \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442, \u0447\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442\u044c \u0441 \u043d\u0435\u0439. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0437\u0430\u0434\u0430\u0447 \u0432\u0432\u043e\u0434\u0430\/\u0432\u044b\u0432\u043e\u0434\u0430. \u0422\u043e \u0435\u0441\u0442\u044c \u0446\u0438\u043a\u043b \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u0442 \u0437\u0430\u0434\u0430\u0447\u0443, \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442 \u0438 \u0432 \u043d\u0443\u0436\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u0435\u0435 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443. <\/p>\n<p>  <b>\u041a\u043e\u0440\u0443\u0442\u0438\u043d\u044b (coroutines)<\/b> \u2014 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0442 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u044d\u0442\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0435\u0439 \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u0446\u0438\u043a\u043b\u0443 \u0441\u043e\u0431\u044b\u0442\u0438\u0439, \u0442\u043e \u0435\u0441\u0442\u044c \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0442 \u0438\u0445 \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u044c. \u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e, \u0447\u0442\u043e\u0431\u044b \u044d\u0442\u0438 \u0441\u043e\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0431\u044b\u043b\u0438 \u0437\u0430\u043f\u0443\u0449\u0435\u043d\u044b \u0438\u043c\u0435\u043d\u043d\u043e \u0447\u0435\u0440\u0435\u0437 \u0446\u0438\u043a\u043b \u0441\u043e\u0431\u044b\u0442\u0438\u0439.<\/p>\n<p>  \u0422\u0430\u043a\u0436\u0435 \u0435\u0441\u0442\u044c <b>\u0444\u0443\u0442\u0443\u0440\u044b<\/b> \u2014 \u043e\u0431\u044a\u0435\u043a\u0442\u044b, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043a\u0430\u043a\u043e\u0439-\u043b\u0438\u0431\u043e \u0437\u0430\u0434\u0430\u0447\u0438. \u042d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0437\u0430\u0434\u0430\u0447\u0430 \u0435\u0449\u0451 \u043d\u0435 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u0430 \u0438\u043b\u0438 \u0443\u0436\u0435 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442; \u0430 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0432\u043e\u043e\u0431\u0449\u0435 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435.<\/p>\n<p>  \u0412 \u0446\u0435\u043b\u043e\u043c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 Asyncio \u043d\u0430 \u0441\u043b\u0443\u0445\u0443, \u043e\u0434\u043d\u0430\u043a\u043e, \u0443 \u043d\u0435\u0435 \u0435\u0441\u0442\u044c \u0440\u044f\u0434 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043a\u0430\u043a \u0440\u0430\u0437 \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u0430 \u0437\u0430\u043a\u0440\u044b\u0442\u044c Trio. <\/p>\n<h3>Trio<\/h3>\n<p>  \u041a\u0430\u043a \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0441\u0430\u043c \u0430\u0432\u0442\u043e\u0440 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 <b>\u041d\u0430\u0442\u0430\u043d\u0438\u044f\u043b \u0421\u043c\u0438\u0442<\/b>, \u0440\u0430\u0437\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u044f Trio, \u043e\u043d \u0441\u0442\u0440\u0435\u043c\u0438\u043b\u0441\u044f \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043b\u0435\u0433\u043a\u043e\u0432\u0435\u0441\u043d\u044b\u0439 \u0438 \u043b\u0435\u0433\u043a\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 \u0434\u043b\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u043b \u0431\u044b \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439 \u0432\u0432\u043e\u0434\/\u0432\u044b\u0445\u043e\u0434 \u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u043e\u0448\u0438\u0431\u043e\u043a.<\/p>\n<p>  \u0412\u0430\u0436\u043d\u0430\u044f \u0444\u0438\u0448\u043a\u0430 Trio \u2013 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439 \u043c\u0435\u043d\u0435\u0434\u0436\u043c\u0435\u043d\u0442 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043d\u0435\u0442 \u0432 Asyncio. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0430\u0432\u0442\u043e\u0440 \u0441\u043e\u0437\u0434\u0430\u043b \u0432 Trio \u0442\u0430\u043a \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u0443\u044e <b>\u00ab\u0434\u0435\u0442\u0441\u043a\u0443\u044e\u00bb<\/b>(nursery) \u2014 \u043e\u0431\u043b\u0430\u0441\u0442\u044c \u043e\u0442\u043c\u0435\u043d\u044b, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0435\u0440\u0435\u0442 \u043d\u0430 \u0441\u0435\u0431\u044f \u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u0437\u0430 \u0430\u0442\u043e\u043c\u0430\u0440\u043d\u043e\u0441\u0442\u044c (\u043d\u0435\u043f\u0440\u0435\u0440\u044b\u0432\u043d\u043e\u0441\u0442\u044c) \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0433\u0440\u0443\u043f\u043f\u044b \u043f\u043e\u0442\u043e\u043a\u043e\u0432. \u041a\u043b\u044e\u0447\u0435\u0432\u0430\u044f \u0438\u0434\u0435\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e, \u0435\u0441\u043b\u0438 \u0432 \u00ab\u0434\u0435\u0442\u0441\u043a\u043e\u0439\u00bb \u043e\u0434\u043d\u0430 \u0438\u0437 \u043a\u043e\u0440\u0443\u0442\u0438\u043d \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u0442\u0441\u044f \u043e\u0448\u0438\u0431\u043a\u043e\u0439, \u0442\u043e \u0432\u0441\u0435 \u043f\u043e\u0442\u043e\u043a\u0438 \u0432 \u00ab\u0434\u0435\u0442\u0441\u043a\u043e\u0439\u00bb \u0431\u0443\u0434\u0443\u0442 \u0438\u043b\u0438 \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u044b \u0438\u043b\u0438 \u043e\u0442\u043c\u0435\u043d\u0435\u043d\u044b. \u0412 \u043b\u044e\u0431\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0440\u0430\u0431\u043e\u0442\u044b \u0431\u0443\u0434\u0435\u0442 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u0435\u043d. \u0418 \u0442\u043e\u043b\u044c\u043a\u043e \u043a\u043e\u0433\u0434\u0430 \u0432\u0441\u0435 \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u0431\u0443\u0434\u0443\u0442 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u044b, \u043f\u043e\u0441\u043b\u0435 \u0432\u044b\u0445\u043e\u0434\u0430 \u0438\u0437 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0443\u0436\u0435 \u0441\u0430\u043c \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043a\u0430\u043a \u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0434\u0430\u043b\u044c\u0448\u0435. <\/p>\n<p>  \u0422\u043e \u0435\u0441\u0442\u044c \u00ab\u0434\u0435\u0442\u0441\u043a\u0430\u044f\u00bb \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0440\u0435\u0434\u043e\u0442\u0432\u0440\u0430\u0442\u0438\u0442\u044c \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043e\u0448\u0438\u0431\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043a \u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u043b\u0438\u0431\u043e \u0432\u0441\u0435 \u00ab\u0443\u043f\u0430\u0434\u0435\u0442\u00bb, \u043b\u0438\u0431\u043e \u043d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435 \u0431\u0443\u0434\u0435\u0442 \u043d\u0435\u0432\u0435\u0440\u043d\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442.<br \/>  \u042d\u0442\u043e \u0438\u043c\u0435\u043d\u043d\u043e \u0442\u043e, \u0447\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0442\u0438 \u0441 Asyncio, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0432 Asyncio \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0440\u0430\u0431\u043e\u0442\u044b \u043d\u0435 \u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442\u0441\u044f, \u043d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0442\u043e \u0447\u0442\u043e \u0441\u043b\u0443\u0447\u0438\u043b\u0430\u0441\u044c \u043e\u0448\u0438\u0431\u043a\u0430. \u0418 \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0432\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0437\u043d\u0430\u0442\u044c, \u0447\u0442\u043e \u0438\u043c\u0435\u043d\u043d\u043e \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u043e \u0432 \u043c\u043e\u043c\u0435\u043d\u0442 \u043e\u0448\u0438\u0431\u043a\u0438, \u0432\u043e-\u0432\u0442\u043e\u0440\u044b\u0445, \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u0441\u044f.<\/p>\n<h3>\u041f\u0440\u0438\u043c\u0435\u0440\u044b <\/h3>\n<p>  \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0438\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u0438\u0437 \u0434\u0432\u0443\u0445 \u043a\u043e\u043d\u043a\u0443\u0440\u0438\u0440\u0443\u044e\u0449\u0438\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439:<\/p>\n<p>  <b>Asyncio<\/b><\/p>\n<pre><code class=\"python\">import asyncio  async def foo1():     print('  foo1: \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f')     await asyncio.sleep(2)     print('  foo1: \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d')  async def foo2():     print('  foo2: \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f')     await asyncio.sleep(1)     print('  foo2: \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d')  loop = asyncio.get_event_loop() bundle = asyncio.wait([     loop.create_task(foo1()),     loop.create_task(foo2()), ]) try:     loop.run_until_complete(bundle) finally:     loop.close()<\/code><\/pre>\n<p>  <b>Trio<\/b><\/p>\n<pre><code class=\"python\">import trio  async def foo1():     print('  foo1: \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f')     await trio.sleep(2)     print('  foo1: \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d')  async def foo2():     print('  foo2: \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f')     await trio.sleep(1)     print('  foo2: \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d')  async def root():     async with trio.open_nursery() as nursery:         nursery.start_soon(foo1)         nursery.start_soon(foo2)  trio.run(root)<\/code><\/pre>\n<p>  \u0432 \u043e\u0431\u043e\u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0431\u0443\u0434\u0435\u0442 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432:<\/p>\n<pre><code class=\"python\">foo1: \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f foo2: \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f foo2: \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d foo1: \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d<\/code><\/pre>\n<p>  \u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043d\u043e \u043a\u043e\u0434 Asyncio \u0438 Trio \u0432 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043f\u043e\u0445\u043e\u0436.<\/p>\n<p>  \u042f\u0432\u043d\u043e\u0435 \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e Trio \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u044f\u0432\u043d\u043e\u0433\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0446\u0438\u043a\u043b\u0430 \u0441\u043e\u0431\u044b\u0442\u0438\u0439.<\/p>\n<p>  \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0447\u0443\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u0436\u0438\u0432\u043e\u0439 \u043f\u0440\u0438\u043c\u0435\u0440. \u0421\u0434\u0435\u043b\u0430\u0435\u043c \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u043a web-\u0441\u0435\u0440\u0432\u0438\u0441\u0443 \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f timestamp.<\/p>\n<p>  \u0414\u043b\u044f Asyncio \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e <b>aiohttp<\/b>:<\/p>\n<pre><code class=\"python\">import time import asyncio import aiohttp  URL = 'https:\/\/yandex.ru\/time\/sync.json?geo=213' MAX_CLIENTS = 5  async def foo(session, i):     start = time.time()     async with session.get(URL) as response:         content = await response.json()         print(f'{i} | {content.get(&quot;time&quot;)} (\u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043e \u0437\u0430 {time.time() - start})')  async def root():     start = time.time()     async with aiohttp.ClientSession() as session:         tasks = [             asyncio.ensure_future(foo(session, i))             for i in range(MAX_CLIENTS)         ]         await asyncio.wait(tasks)     print(f'\u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u043e \u0437\u0430 {time.time() - start}')  ioloop = asyncio.get_event_loop() try:     ioloop.run_until_complete(root()) finally:     ioloop.close()<\/code><\/pre>\n<p>  \u0414\u043b\u044f Trio \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f <b>asks<\/b>:<\/p>\n<pre><code class=\"python\">import trio import time import asks URL = 'https:\/\/yandex.ru\/time\/sync.json?geo=213' MAX_CLIENTS = 5  asks.init('trio')  async def foo(i):     start = time.time()     response = await asks.get(URL)     content = response.json()     print(f'{i} | {content.get(&quot;time&quot;)} (\u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043e \u0437\u0430 {time.time() - start})')  async def root():     start = time.time()     async with trio.open_nursery() as nursery:         for i in range(MAX_CLIENTS):             nursery.start_soon(foo, i)      print(f'\u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u043e \u0437\u0430 {time.time() - start}')  trio.run(root) <\/code><\/pre>\n<p>  \u0412 \u043e\u0431\u043e\u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0447\u0442\u043e-\u0442\u043e \u0432\u0440\u043e\u0434\u0435<\/p>\n<pre><code class=\"python\">0 | 1543837647522 (\u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043e \u0437\u0430 0.11855053901672363) 2 | 1543837647535 (\u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043e \u0437\u0430 0.1389765739440918) 3 | 1543837647527 (\u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043e \u0437\u0430 0.13904547691345215) 4 | 1543837647557 (\u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043e \u0437\u0430 0.1591191291809082) 1 | 1543837647607 (\u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043e \u0437\u0430 0.2100353240966797) \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u043e \u0437\u0430 0.2102828025817871<\/code><\/pre>\n<p>  \u0425\u043e\u0440\u043e\u0448\u043e. \u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c, \u0447\u0442\u043e \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043e\u0434\u043d\u043e\u0439 \u0438\u0437 \u043a\u043e\u0440\u0443\u0442\u0438\u043d \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u0430 \u043e\u0448\u0438\u0431\u043a\u0430<br \/>  \u0434\u043b\u044f Asyncio.<\/p>\n<pre><code class=\"python\">async def foo(session, i):     start = time.time()     if i == 3:         raise Exception     async with session.get(URL) as response:         content = await response.json()         print(f'{i} | {content.get(&quot;time&quot;)} (\u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043e \u0437\u0430 {time.time() - start})')  1 | 1543839060815 (\u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043e \u0437\u0430 0.10857725143432617) 2 | 1543839060844 (\u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043e \u0437\u0430 0.10372781753540039) 5 | 1543839060843 (\u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043e \u0437\u0430 0.10734415054321289) 4 | 1543839060874 (\u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043e \u0437\u0430 0.13985681533813477) \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u043e \u0437\u0430 0.15044045448303223 Traceback (most recent call last):   File &quot;...py&quot;, line 12, in foo     raise Exception Exception<\/code><\/pre>\n<p>  \u0434\u043b\u044f Trio<\/p>\n<pre><code class=\"python\">async def foo(i):     start = time.time()     response = await asks.get(URL)     content = response.json()     if i == 3:         raise Exception     print(f'{i} | {content.get(&quot;time&quot;)} (\u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043e \u0437\u0430 {time.time() - start})')   4 | 1543839223372 (\u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043e \u0437\u0430 0.13524699211120605) 2 | 1543839223379 (\u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043e \u0437\u0430 0.13848185539245605) Traceback (most recent call last):   File &quot;...py&quot;, line 28, in &lt;module&gt;     trio.run(root)   File &quot;\/lib64\/python3.6\/site-packages\/trio\/_core\/_run.py&quot;, line 1337, in run     raise runner.main_task_outcome.error   File &quot;...py&quot;, line 23, in root     nursery.start_soon(foo, i)   File &quot;\/lib64\/python3.6\/site-packages\/trio\/_core\/_run.py&quot;, line 397, in __aexit__     raise combined_error_from_nursery   File &quot;...py&quot;, line 15, in foo     raise Exception Exception<\/code><\/pre>\n<p>  \u041d\u0430\u0433\u043b\u044f\u0434\u043d\u043e \u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u0432 Trio \u0441\u0440\u0430\u0437\u0443 \u043f\u043e \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u043e\u0432\u0435\u043d\u0438\u044e \u043e\u0448\u0438\u0431\u043a\u0438 \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u043b\u0430 \u00ab\u043e\u0431\u043b\u0430\u0441\u0442\u044c \u043e\u0442\u043c\u0435\u043d\u044b\u00bb, \u0438 \u0434\u0432\u0435 \u0438\u0437 \u0447\u0435\u0442\u044b\u0440\u0435\u0445 \u0437\u0430\u0434\u0430\u0447, \u043d\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0445 \u043e\u0448\u0438\u0431\u043a\u0438, \u0431\u044b\u043b\u0438 \u0430\u0432\u0430\u0440\u0438\u0439\u043d\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u044b.<\/p>\n<p>  \u0412 Asyncio \u0436\u0435 \u0431\u044b\u043b\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u044b \u0432\u0441\u0435 \u0437\u0430\u0434\u0430\u0447\u0438, \u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0442\u043e\u043c \u043f\u043e\u044f\u0432\u0438\u043b\u0441\u044f \u0442\u0440\u044d\u0439\u0441\u0431\u044d\u043a.<\/p>\n<p>  \u0412 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u044d\u0442\u043e \u043d\u0435 \u0432\u0430\u0436\u043d\u043e, \u043d\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c, \u0447\u0442\u043e \u0437\u0430\u0434\u0430\u0447\u0438 \u0442\u0430\u043a \u0438\u043b\u0438 \u0438\u043d\u0430\u0447\u0435 \u0437\u0430\u0432\u0438\u0441\u044f\u0442 \u0434\u0440\u0443\u0433 \u043e\u0442 \u0434\u0440\u0443\u0433\u0430, \u0438 \u043d\u0430\u0431\u043e\u0440 \u0437\u0430\u0434\u0430\u0447 \u0434\u043e\u043b\u0436\u0435\u043d \u043e\u0431\u043b\u0430\u0434\u0430\u0442\u044c \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e\u043c \u0430\u0442\u043e\u043c\u0430\u0440\u043d\u043e\u0441\u0442\u0438. \u0412 \u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0441\u0432\u043e\u0435\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0435 \u0440\u0435\u0430\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u0430 \u043e\u0448\u0438\u0431\u043a\u0443 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043a\u0443\u0434\u0430 \u0432\u0430\u0436\u043d\u0435\u0435. \u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c<i> await asyncio.wait(tasks, return_when=FIRST_EXCEPTION)<\/i>, \u043d\u043e \u043d\u0430\u0434\u043e \u043d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0442\u044c \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0442\u044c \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u0435 \u0437\u0430\u0434\u0430\u0447\u0438.<\/p>\n<p>  \u0410 \u0432\u043e\u0442 \u0435\u0449\u0435 \u043e\u0434\u0438\u043d \u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<p>  \u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u0447\u0442\u043e \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u043e\u0431\u0440\u0430\u0449\u0430\u044e\u0442\u0441\u044f \u043a \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u043c web-\u0441\u0435\u0440\u0432\u0438\u0441\u0430\u043c, \u0438 \u0432\u0430\u0436\u0435\u043d \u043f\u0435\u0440\u0432\u044b\u0439 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442.<\/p>\n<pre><code class=\"python\">import asyncio from asyncio import FIRST_COMPLETED import aiohttp  URL = 'https:\/\/yandex.ru\/time\/sync.json?geo=213' MAX_CLIENTS = 5  async def foo(session):     async with session.get(URL) as response:         content = await response.json()         return content.get(&quot;time&quot;)  async def root():     async with aiohttp.ClientSession() as session:         tasks = [             asyncio.ensure_future(foo(session))             for i in range(1, MAX_CLIENTS + 1)         ]         done, pending = await asyncio.wait(tasks, return_when=FIRST_COMPLETED)         print(done.pop().result())         for future in pending:             future.cancel()  ioloop = asyncio.get_event_loop() try:     ioloop.run_until_complete(root()) except:     ioloop.close()<\/code><\/pre>\n<p>  \u0412\u0441\u0435 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e. \u0415\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u0435 \u2014 \u043d\u0435 \u0437\u0430\u0431\u044b\u0442\u044c \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u0431\u044b\u043b\u0438 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u044b.<\/p>\n<p>  \u0412 Trio \u043f\u0440\u043e\u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u0439 \u043c\u0430\u043d\u0435\u0432\u0440 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u043b\u043e\u0436\u043d\u0435\u0435, \u0437\u0430\u0442\u043e \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043d\u0435\u0437\u0430\u043c\u0435\u0442\u043d\u044b\u0435 \u0441\u0440\u0430\u0437\u0443 \u00ab\u0445\u0432\u043e\u0441\u0442\u044b\u00bb:<\/p>\n<pre><code class=\"python\">import trio import asks URL = 'https:\/\/yandex.ru\/time\/sync.json?geo=213' MAX_CLIENTS = 5 asks.init('trio')  async def foo(session, send_channel, nursery):     response = await session.request('GET', url=URL)     content = response.json()     async with send_channel:         send_channel.send_nowait(content.get(&quot;time&quot;))     nursery.cancel_scope.cancel()  async def root():     send_channel, receive_channel = trio.open_memory_channel(1)     async with send_channel, receive_channel:         async with trio.open_nursery() as nursery:             async with asks.Session() as session:                 for i in range(MAX_CLIENTS):                     nursery.start_soon(foo, session, send_channel.clone(), nursery)          async with receive_channel:             x = await receive_channel.receive()             print(x)  trio.run(root)<\/code><\/pre>\n<p>  <i>nursery.cancel_scope.cancel()<\/i> \u2014 \u043f\u0435\u0440\u0432\u0430\u044f \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0432\u0448\u0430\u044f \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u0430 \u0432\u044b\u0437\u043e\u0432\u0435\u0442 \u0432 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u043e\u0442\u043c\u0435\u043d\u044b \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043e\u0442\u043c\u0435\u043d\u0438\u0442 \u0432\u0441\u0435 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0437\u0430\u0434\u0430\u0447\u0438, \u0442\u0430\u043a \u0447\u0442\u043e \u043d\u0435 \u043d\u0430\u0434\u043e \u0437\u0430\u0431\u043e\u0442\u0438\u0442\u044c\u0441\u044f \u043e\u0431 \u044d\u0442\u043e\u043c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e.<br \/>  \u041f\u0440\u0430\u0432\u0434\u0430, \u0447\u0442\u043e\u0431\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043a\u043e\u0440\u0443\u0442\u0438\u043d\u044b \u0432 \u0432\u044b\u0437\u0432\u0430\u0432\u0448\u0443\u044e \u0435\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0438\u043d\u0438\u0446\u0438\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u043d\u0430\u043b \u0441\u0432\u044f\u0437\u0438.<\/p>\n<p>  \u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u044d\u0442\u043e\u0442 \u0441\u0440\u0430\u0432\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043e\u0431\u0437\u043e\u0440 \u0434\u0430\u043b \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0435\u0439 Trio. \u0412\u0441\u0435\u043c \u0441\u043f\u0430\u0441\u0438\u0431\u043e!<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/company\/barsgroup\/blog\/490872\/\"> https:\/\/habr.com\/ru\/company\/barsgroup\/blog\/490872\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/company\/barsgroup\/blog\/490872\/\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/m7\/0o\/ye\/m70oyejwkcwdk32csx1mq2wprao.jpeg\" alt=\"image\"><\/p>\n<p>  \u0412 Python \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 <a href=\"https:\/\/github.com\/python-trio\/trio\">Trio <\/a>\u2013 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f.<br \/>  \u0417\u043d\u0430\u043a\u043e\u043c\u0441\u0442\u0432\u043e \u0441 Trio \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c \u0431\u0443\u0434\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u0442\u0435\u043c, \u043a\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043d\u0430 Asyncio, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u044d\u0442\u043e \u0445\u043e\u0440\u043e\u0448\u0430\u044f \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u0430, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0430\u044f \u0440\u0435\u0448\u0430\u0442\u044c \u0447\u0430\u0441\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c, \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c\u0441\u044f Asyncio. \u0412 \u044d\u0442\u043e\u043c \u043e\u0431\u0437\u043e\u0440\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u0447\u0442\u043e \u0438\u0437 \u0441\u0435\u0431\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 Trio \u0438 \u043a\u0430\u043a\u0438\u0435 \u0444\u0438\u0447\u0438 \u043e\u043d\u0430 \u043d\u0430\u043c \u0434\u0430\u0435\u0442.   <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-299703","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/299703","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=299703"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/299703\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=299703"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=299703"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=299703"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}