{"id":218423,"date":"2014-04-07T01:05:02","date_gmt":"2014-04-06T21:05:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=218423"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=218423","title":{"rendered":"<span class=\"post_title\">\u0420\u0430\u0431\u043e\u0442\u0430 \u0441 ZeroMQ \u0438 PostgreSQL \u0432 asyncio<\/span>"},"content":{"rendered":"<div class=\"content html_format\">   \t\u041d\u0430\u0432\u0435\u0440\u043d\u043e\u0435, \u0432\u0441\u0435 \u0443\u0436\u0435 \u0441\u043b\u044b\u0448\u0430\u043b\u0438 \u043e \u0447\u0443\u0434\u0435\u0441\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435 <a href=\"https:\/\/docs.python.org\/dev\/library\/asyncio.html\">asyncio<\/a>?<\/p>\n<p>  \u0415\u0441\u043b\u0438 \u043d\u0435\u0442, \u0442\u043e \u043a\u043e\u0440\u043e\u0442\u043a\u043e: \u044d\u0442\u0430 \u043b\u0438\u0431\u0430 \u0441\u0442\u0430\u043b\u0430 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043e\u043c \u043d\u0430 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0435 \u0441\u0435\u0442\u0435\u0432\u043e\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u0430 Python. <b>tornado<\/b> \u0438 <b>twisted<\/b> \u0438\u043b\u0438 \u043d\u0430\u0443\u0447\u0430\u0442\u0441\u044f \u0441 \u043d\u0435\u0439 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0438\u043b\u0438 \u043f\u043e\u0441\u0442\u0435\u043f\u0435\u043d\u043d\u043e \u0443\u0439\u0434\u0443\u0442 \u0432 \u043c\u0430\u0440\u0433\u0438\u043d\u0430\u043b\u044b.<\/p>\n<p>  <b>asyncio<\/b> \u043f\u0440\u0435\u043a\u0440\u0430\u0441\u043d\u0430, \u043d\u043e \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b <i>TCP<\/i>, <i>UDP<\/i>, <i>UNIX<\/i> \u0441\u043e\u043a\u0435\u0442\u0430\u043c\u0438, <i>PIPES<\/i> \u0438 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u043c \u0437\u0430\u043f\u0443\u0441\u043a\u043e\u043c <i>subprocess<\/i>.<\/p>\n<p>  \u0427\u0442\u043e\u0431\u044b \u0432\u0441\u0435\u043c \u0431\u044b\u043b\u043e \u0437\u0434\u043e\u0440\u043e\u0432\u043e \u043d\u0443\u0436\u043d\u044b \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438, \u0443\u043c\u0435\u044e\u0449\u0438\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 <i>asyncio<\/i>. \u041a\u043e\u0435-\u0447\u0442\u043e \u0443\u0436\u0435 \u0435\u0441\u0442\u044c, \u043d\u043e \u043c\u0430\u043b\u043e.<\/p>\n<p>  \u0412\u043e\u0442 \u044f \u0441 \u043a\u043e\u043b\u043b\u0435\u0433\u0430\u043c\u0438 \u0438 \u0441\u0434\u0435\u043b\u0430\u043b \u043f\u0430\u0440\u0443: \u043e\u0434\u043d\u0443 \u0434\u043b\u044f <a href=\"http:\/\/zeromq.org\/\">ZeroMQ<\/a> \u0438 \u0434\u0440\u0443\u0433\u0443\u044e \u0434\u043b\u044f <a href=\"http:\/\/www.postgresql.org\/\">PostgreSQL<\/a><\/p>\n<p>  <i>\u0415\u0441\u043b\u0438 \u0432\u044b \u043f\u0440\u043e\u0447\u043d\u043e \u0441\u0438\u0434\u0438\u0442\u0435 \u043d\u0430 Python 2 \u0438 \u043d\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u0435\u0442\u0435\u0441\u044c Python 3 \u2014 \u043d\u0435 \u0445\u043e\u0434\u0438\u0442\u0435 \u043f\u043e\u0434 \u043a\u0430\u0442 \u0432\u043e \u0438\u0437\u0431\u0435\u0436\u0430\u043d\u0438\u0435 \u0433\u043b\u0443\u043f\u044b\u0445 \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432 \u0438 \u043f\u0440\u043e\u0447\u0438\u0445 \u043d\u0435\u0434\u043e\u0440\u0430\u0437\u0443\u043c\u0435\u043d\u0438\u0439<\/i>.<br \/>  <a name=\"habracut\"><\/a><\/p>\n<p>  \u0417\u0430\u0447\u0435\u043c \u043e\u043d\u043e \u043c\u043d\u0435 \u0431\u044b\u043b\u043e \u043d\u0430\u0434\u043e? <\/p>\n<p>  \u041f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043c\u044b \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u043c \u043d\u043e\u0432\u044b\u0439 \u043f\u0440\u043e\u0435\u043a\u0442 \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0431\u0435\u0437 <i>ZeroMQ<\/i> \u0438 <i>Postgress<\/i> \u043d\u0435 \u043e\u0431\u043e\u0439\u0442\u0438\u0441\u044c. \u041e\u0447\u0435\u043d\u044c \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0430 <i>asyncio<\/i>. \u041f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0437\u0430\u043f\u0438\u043b\u0438\u0442\u044c \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u044e\u0449\u0438\u0435 \u043a\u0443\u0441\u043e\u0447\u043a\u0438.<\/p>\n<p>  \u0421\u0440\u0430\u0437\u0443 \u0441\u043a\u0430\u0436\u0443, \u043e\u0431\u0435 \u043b\u0438\u0431\u044b \u0434\u043e\u0431\u0440\u043e\u0442\u043d\u044b\u0435. \u042f <b>Python Core Developer<\/b> \u0438 \u0432 \u043a\u043e\u0434\u0435 <b>asyncio<\/b> \u0442\u043e\u0436\u0435 \u0435\u0441\u0442\u044c \u043d\u0435\u043c\u0430\u043b\u043e \u043c\u043e\u0435\u0433\u043e \u0442\u0440\u0443\u0434\u0430. \u0414\u0443\u043c\u0430\u044e, \u044f \u043f\u043e\u043d\u044f\u043b \u043a\u0430\u043a \u0445\u043e\u0440\u043e\u0448\u043e \u043f\u0438\u0441\u0430\u0442\u044c \u0434\u043b\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u044b, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0441\u0430\u043c \u0436\u0435 \u043f\u043e\u043c\u043e\u0433\u0430\u043b \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c.<\/p>\n<p>  \u041f\u043b\u044e\u0441 (\u043f\u043e\u0447\u0442\u0438) 100% \u043f\u043e\u043a\u0440\u044b\u0442\u0438\u0435 \u043a\u043e\u0434\u0430 \u043e\u0431\u043e\u0438\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a \u0442\u0435\u0441\u0442\u0430\u043c\u0438 \u0438 \u0432\u043d\u044f\u0442\u043d\u0430\u044f (\u043d\u0430\u0434\u0435\u044e\u0441\u044c) \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f.<\/p>\n<p>  <b>aiozmq<\/b> \u2014 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <i>ZeroMQ \u0441\u043e\u043a\u0435\u0442\u044b<\/i> \u0441 <i>asyncio<\/i>.<\/p>\n<p>  \u0414\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f \u2014 <a href=\"http:\/\/aiozmq.readthedocs.org\/\">\u0437\u0434\u0435\u0441\u044c<\/a>.<\/p>\n<p>  <i>aiozmq<\/i> \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441 \u043d\u0438\u0437\u043a\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u044b\u043c\u0438 <i>ZeroMQ \u0441\u043e\u043a\u0435\u0442\u0430\u043c\u0438<\/i> \u0438, \u0433\u043b\u0430\u0432\u043d\u043e\u0435, \u0434\u0430\u0451\u0442 \u0438\u0437 \u043a\u043e\u0440\u043e\u0431\u043a\u0438 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c <i>Remote Procedure Call<\/i> (\u043f\u043b\u044e\u0441 <i>PubSub<\/i> \u0438 <i>Notify<\/i>).<\/p>\n<p>  \u041a\u043e\u0440\u043e\u0442\u043a\u0438\u0439 \u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"python\">    import asyncio     import aiozmq     import aiozmq.rpc      class ServerHandler(aiozmq.rpc.AttrHandler):         @aiozmq.rpc.method         def remote_func(self, a:int, b:int) -&gt; int:             return a + b      @asyncio.coroutine     def go():         server = yield from aiozmq.rpc.start_server(             ServerHandler(), bind='tcp:\/\/127.0.0.1:5555')         client = yield from aiozmq.rpc.open_client(             connect='tcp:\/\/127.0.0.1:5555')          ret = yield from client.rpc.remote_func(1, 2)         assert 3 == ret          server.close()         client.close()      asyncio.set_event_loop_policy(aiozmq.ZmqEventLoopPolicy())     asyncio.get_event_loop().run_until_complete(go()) <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043a <b>aiopg<\/b><\/p>\n<p>  \u042d\u0442\u0430 \u043b\u0438\u0431\u0430 \u0443\u043c\u0435\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 <i>psycopg2<\/i> \u0432 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u043c \u0440\u0435\u0436\u0438\u043c\u0435 \u0438 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0438\u044f\u0442\u043d\u043e\u0433\u043e \u0431\u043e\u043d\u0443\u0441\u0430 \u0434\u0430\u0451\u0442 <b>connection pool<\/b><\/p>\n<p>  \u0414\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f \u2014 <a href=\"http:\/\/aiopg.readthedocs.org\/\">\u0437\u0434\u0435\u0441\u044c<\/a>.<\/p>\n<pre><code class=\"python\">    @asyncio.coroutine     def test_select():         pool = yield from aiopg.create_pool(dsn)          with (yield from pool.cursor()) as cur:             yield from cur.execute('SELECT 1')             ret = yield from cur.fetchone()             assert ret == (1,), ret  <\/code><\/pre>\n<p>  \u041e\u0431\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0432\u044b\u043b\u043e\u0436\u0435\u043d\u044b \u043d\u0430 GitHub: <a href=\"https:\/\/github.com\/aio-libs\/aiozmq\">aiozmq<\/a> \u0438 <a href=\"https:\/\/github.com\/aio-libs\/aiopg\">aiopg<\/a><\/p>\n<p>  \u041f\u0440\u043e\u0431\u0443\u0439\u0442\u0435, \u0435\u0441\u043b\u0438 \u043f\u043e\u043d\u0440\u0430\u0432\u0438\u043b\u043e\u0441\u044c \u2014 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435.<\/p>\n<p>  \u041d\u0430\u0439\u0434\u0435\u0442\u0435 \u0431\u0430\u0433\u0438 \u2014 \u043f\u0438\u0448\u0438\u0442\u0435 \u043d\u0430 \u0433\u0438\u0442\u0445\u0430\u0431\u0435 \u0432 <i>issues<\/i>, \u0430 \u0435\u0449\u0451 \u043b\u0443\u0447\u0448\u0435 \u0441\u0440\u0430\u0437\u0443 \u0434\u0435\u043b\u0430\u0439\u0442\u0435 <i>pull request<\/i>    \t<\/p>\n<div class=\"clear\"><\/div>\n<\/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=\"http:\/\/habrahabr.ru\/post\/218423\/\"> http:\/\/habrahabr.ru\/post\/218423\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">   \t\u041d\u0430\u0432\u0435\u0440\u043d\u043e\u0435, \u0432\u0441\u0435 \u0443\u0436\u0435 \u0441\u043b\u044b\u0448\u0430\u043b\u0438 \u043e \u0447\u0443\u0434\u0435\u0441\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435 <a href=\"https:\/\/docs.python.org\/dev\/library\/asyncio.html\">asyncio<\/a>?<\/p>\n<p>  \u0415\u0441\u043b\u0438 \u043d\u0435\u0442, \u0442\u043e \u043a\u043e\u0440\u043e\u0442\u043a\u043e: \u044d\u0442\u0430 \u043b\u0438\u0431\u0430 \u0441\u0442\u0430\u043b\u0430 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043e\u043c \u043d\u0430 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0435 \u0441\u0435\u0442\u0435\u0432\u043e\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u0430 Python. <b>tornado<\/b> \u0438 <b>twisted<\/b> \u0438\u043b\u0438 \u043d\u0430\u0443\u0447\u0430\u0442\u0441\u044f \u0441 \u043d\u0435\u0439 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0438\u043b\u0438 \u043f\u043e\u0441\u0442\u0435\u043f\u0435\u043d\u043d\u043e \u0443\u0439\u0434\u0443\u0442 \u0432 \u043c\u0430\u0440\u0433\u0438\u043d\u0430\u043b\u044b.<\/p>\n<p>  <b>asyncio<\/b> \u043f\u0440\u0435\u043a\u0440\u0430\u0441\u043d\u0430, \u043d\u043e \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b <i>TCP<\/i>, <i>UDP<\/i>, <i>UNIX<\/i> \u0441\u043e\u043a\u0435\u0442\u0430\u043c\u0438, <i>PIPES<\/i> \u0438 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u043c \u0437\u0430\u043f\u0443\u0441\u043a\u043e\u043c <i>subprocess<\/i>.<\/p>\n<p>  \u0427\u0442\u043e\u0431\u044b \u0432\u0441\u0435\u043c \u0431\u044b\u043b\u043e \u0437\u0434\u043e\u0440\u043e\u0432\u043e \u043d\u0443\u0436\u043d\u044b \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438, \u0443\u043c\u0435\u044e\u0449\u0438\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 <i>asyncio<\/i>. \u041a\u043e\u0435-\u0447\u0442\u043e \u0443\u0436\u0435 \u0435\u0441\u0442\u044c, \u043d\u043e \u043c\u0430\u043b\u043e.<\/p>\n<p>  \u0412\u043e\u0442 \u044f \u0441 \u043a\u043e\u043b\u043b\u0435\u0433\u0430\u043c\u0438 \u0438 \u0441\u0434\u0435\u043b\u0430\u043b \u043f\u0430\u0440\u0443: \u043e\u0434\u043d\u0443 \u0434\u043b\u044f <a href=\"http:\/\/zeromq.org\/\">ZeroMQ<\/a> \u0438 \u0434\u0440\u0443\u0433\u0443\u044e \u0434\u043b\u044f <a href=\"http:\/\/www.postgresql.org\/\">PostgreSQL<\/a><\/p>\n<p>  <i>\u0415\u0441\u043b\u0438 \u0432\u044b \u043f\u0440\u043e\u0447\u043d\u043e \u0441\u0438\u0434\u0438\u0442\u0435 \u043d\u0430 Python 2 \u0438 \u043d\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u0435\u0442\u0435\u0441\u044c Python 3 \u2014 \u043d\u0435 \u0445\u043e\u0434\u0438\u0442\u0435 \u043f\u043e\u0434 \u043a\u0430\u0442 \u0432\u043e \u0438\u0437\u0431\u0435\u0436\u0430\u043d\u0438\u0435 \u0433\u043b\u0443\u043f\u044b\u0445 \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432 \u0438 \u043f\u0440\u043e\u0447\u0438\u0445 \u043d\u0435\u0434\u043e\u0440\u0430\u0437\u0443\u043c\u0435\u043d\u0438\u0439<\/i>.  <\/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-218423","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/218423","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=218423"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/218423\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=218423"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=218423"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=218423"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}