{"id":467501,"date":"2025-07-18T22:03:02","date_gmt":"2025-07-18T22:03:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=467501"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=467501","title":{"rendered":"<span>PEP-734: \u0421\u0443\u0431\u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440\u044b \u0432 Python 3.14<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<div class=\"tm-iframe_temp\" data-src=\"https:\/\/embedd.srv.habr.com\/iframe\/6874c747aadce8eb96cafb49\" data-style=\"\" id=\"6874c747aadce8eb96cafb49\" width=\"\"><\/div>\n<p>\u041f\u0440\u0438\u0432\u0435\u0442! \u041c\u0435\u043d\u044f \u0437\u043e\u0432\u0443\u0442 \u041d\u0438\u043a\u0438\u0442\u0430 \u0421\u043e\u0431\u043e\u043b\u0435\u0432, \u044f core-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u044f\u0437\u044b\u043a\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f CPython, \u0430 \u0442\u0430\u043a \u0436\u0435 \u0430\u0432\u0442\u043e\u0440 \u0441\u0435\u0440\u0438\u0438 \u0432\u0438\u0434\u0435\u043e \u043f\u0440\u043e \u0435\u0433\u043e \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e.<\/p>\n<p>\u042f \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u044e \u0441\u0432\u043e\u0439 \u0446\u0438\u043a\u043b \u0441\u0442\u0430\u0442\u0435\u0439 \u043d\u0430 \u0445\u0430\u0431\u0440\u0435 \u043f\u0440\u043e \u0434\u0435\u0442\u0430\u043b\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u0438\u0442\u043e\u043d\u0430. \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043f\u0440\u043e \u0441\u0443\u0431\u0438\u043d\u0442\u0435\u0440\u043f\u0435\u0440\u0442\u0430\u0442\u043e\u0440\u044b, \u0438\u0445 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e, \u043f\u0440\u043e\u0448\u043b\u043e\u0435 \u0438, \u043d\u0430\u0434\u0435\u044e\u0441\u044c, \u0441\u0432\u0435\u0442\u043b\u043e\u0435 \u0431\u0443\u0434\u0443\u0449\u0435\u0435. <\/p>\n<p>\u041f\u043e\u0434 \u043a\u0430\u0442\u043e\u043c \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e: \u043d\u043e\u0432\u044b\u0435 \u043f\u0438\u0442\u043e\u043d\u043e\u0432\u0441\u043a\u0438\u0435 API \u0434\u043b\u044f \u0443\u0441\u043a\u043e\u0440\u0435\u043d\u0438\u044f \u0438 \u043f\u0430\u0440\u0430\u043b\u0435\u043b\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0432\u0430\u0448\u0438\u0445 \u043f\u0440\u043e\u0433\u0440\u0430\u043c, \u043f\u0440\u043e \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u044c\u044e, \u043f\u0440\u043e \u0434\u0443\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445. \u041d\u0443 \u0438 \u043c\u043d\u043e\u0433\u043e C \u043a\u043e\u0434\u0430!<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0432 \u0432\u043e\u043f\u0440\u043e\u0441\u0435 \u0438 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u0432\u0430\u043c, \u044f \u0441\u0434\u0435\u043b\u0430\u043b \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0430\u0436\u043d\u044b\u0445 \u0448\u0430\u0433\u043e\u0432: \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u043b \u043f\u043e\u0447\u0442\u0438 \u0432\u0435\u0441\u044c \u043a\u043e\u0434 \u0434\u0430\u043d\u043d\u043e\u0439 \u0444\u0438\u0447\u0438, \u043d\u0430\u0447\u0430\u043b \u043a\u043e\u043c\u043c\u0438\u0442\u044c \u0432 \u0441\u0443\u0431\u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440\u044b \u0438 \u0432\u0437\u044f\u043b \u0438\u043d\u0442\u0435\u0440\u0432\u044c\u044e \u0443 \u0430\u0432\u0442\u043e\u0440\u0430 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430. \u0418\u043d\u0442\u0435\u0440\u0432\u044c\u044e \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e \u0441 \u0440\u0443\u0441\u0441\u043a\u0438\u043c\u0438 \u0438 \u0430\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u0438\u043c\u0438 \u0441\u0443\u0431\u0442\u0438\u0442\u0440\u0430\u043c\u0438. \u0410 \u0435\u0449\u0435 \u044f \u0434\u043e\u0431\u0430\u0432\u0438\u043b \u043a\u0443\u0447\u0443 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u043f\u0440\u044f\u043c\u043e \u0432 \u0432\u0438\u0434\u0435\u043e. \u0421\u0442\u0430\u0432\u044c\u0442\u0435 \u043d\u0430 \u043f\u0430\u0443\u0437\u0443 \u0438 \u0447\u0438\u0442\u0430\u0439\u0442\u0435 \u043a\u043e\u0434.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u0432\u0430\u043c \u0442\u0430\u043a\u043e\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u0438\u043b\u0438 \u0446\u0435\u043b\u0438\u043a\u043e\u043c \u043d\u0435\u0437\u043d\u0430\u043a\u043e\u043c\u043e \u2013 \u0434\u043e\u0431\u0440\u043e \u043f\u043e\u0436\u0430\u043b\u043e\u0432\u0430\u0442\u044c!<\/p>\n<hr\/>\n<h2>\u0427\u0442\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u0432 3.14?<\/h2>\n<p>\u0412 Python \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u0434\u0432\u0435 \u0432\u0430\u0436\u043d\u044b\u0435 \u043d\u043e\u0432\u044b\u0435 \u0447\u0430\u0441\u0442\u0438. \u041f\u0435\u0440\u0432\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u2013 <code>concurrent.interpreters<\/code><\/p>\n<pre><code class=\"python\">&gt;&gt;&gt; from concurrent import interpreters  &gt;&gt;&gt; interp = interpreters.create() &gt;&gt;&gt; interpreters.list_all() [Interpreter(0), Interpreter(1)]  &gt;&gt;&gt; def worker(arg: int) -&gt; None: ...     print('do some work', arg) ...      &gt;&gt;&gt; interp.call(worker, 1)  # \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043a\u043e\u0434 \u0432 \u0441\u0430\u0431\u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440\u0435 do some work 1<\/code><\/pre>\n<p>\u041e\u043d\u0430 \u044f\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 <a href=\"https:\/\/github.com\/python\/cpython\/blob\/main\/Lib\/concurrent\/interpreters\/__init__.py\" rel=\"noopener noreferrer nofollow\">Python \u0410\u041f\u0418<\/a> \u0434\u043b\u044f \u0443\u0434\u043e\u0431\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0441\u0443\u0431\u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440\u0430\u043c\u0438. \u0415\u0433\u043e \u043f\u043e\u043a\u0430 \u043d\u0435 \u0442\u0430\u043a \u043c\u043d\u043e\u0433\u043e, \u043d\u043e \u0443\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0435 \u0432\u0435\u0449\u0438. \u0421\u043a\u043e\u0440\u0435\u0435 \u0432\u0441\u0435\u0433\u043e \u2013 \u0432\u0430\u043c \u043e\u043d\u043e \u043d\u0435 \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u0440\u044f\u043c\u043e \u0432 \u0442\u0430\u043a\u043e\u043c \u0432\u0438\u0434\u0435. \u0414\u0430\u043d\u043d\u043e\u0435 \u0410\u041f\u0418 \u0441\u043a\u043e\u0440\u0435\u0435 \u0434\u043b\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a. \u0410\u043d\u0430\u043b\u043e\u0433\u0438\u044f: \u043a\u0430\u043a \u0447\u0430\u0441\u0442\u043e \u0432\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 \u043c\u043e\u0434\u0443\u043b\u044c <code>threading<\/code> \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e?<\/p>\n<p>\u0412\u0442\u043e\u0440\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u2013 <code>concurrent.futures.InterpreterPoolExecutor<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f <a href=\"https:\/\/github.com\/python\/cpython\/blob\/e89923d36650fe10ce1c6b5f7152638589684004\/Lib\/concurrent\/futures\/interpreter.py#L101\" rel=\"noopener noreferrer nofollow\">\u0430\u043d\u0430\u043b\u043e\u0433\u043e\u043c<\/a> <code>concurrent.futures.ThreadPoolExecutor<\/code>. \u041c\u043e\u0436\u043d\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u043a\u0430\u043a\u0443\u044e-\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0443 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u043f\u0430\u0440\u0430\u043b\u0435\u043b\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"python\">&gt;&gt;&gt; from concurrent.futures import InterpreterPoolExecutor  &gt;&gt;&gt; CPUS = 4 ... with InterpreterPoolExecutor(CPUS) as executor: ...     list(executor.map(worker, [1, 2, 3, 4, 5, 6])) ...      do some work 1 do some work 2 do some work 4 do some work 3 do some work 5 do some work 6 [None, None, None, None, None, None]<\/code><\/pre>\n<p>\u0422\u0443\u0442 \u0443\u0436\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0435\u0435. \u0414\u0430\u043d\u043d\u044b\u0439 \u0410\u041f\u0418 \u043c\u043e\u0436\u043d\u043e \u0438 \u043d\u0443\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c, \u0435\u0441\u043b\u0438 \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u0440\u0430\u0441\u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438\u0442\u044c \u0447\u0442\u043e-\u0442\u043e \u043d\u0430 \u043c\u043d\u043e\u0433\u043e \u0441\u0443\u0431\u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440\u043e\u0432.<\/p>\n<p>\u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u2013 \u043a\u0430\u043a \u043e\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442?<\/p>\n<h3>\u0421\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u0441\u0443\u0431\u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440\u043e\u0432 \u0441 threading \/ multiprocessing \/ free-threading \/ asyncio<\/h3>\n<p>\u041c\u043d\u043e\u0433\u043e\u0437\u0430\u0434\u0430\u0447\u043d\u043e\u0441\u0442\u044c (\u0442\u043e\u0447\u043d\u0435\u0435 \u0435\u0451 \u043e\u0442\u0441\u0443\u0442\u0441\u0432\u0438\u0435) \u2013 \u0434\u043e\u043b\u0433\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u0431\u044b\u043b\u0430 \u0441\u043b\u0430\u0431\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u043e\u0439 CPython. \u0411\u044b\u043b\u043e \u043f\u0440\u0435\u0434\u043f\u0440\u0438\u043d\u044f\u0442\u043e \u043c\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u043d\u044b\u0445 \u043f\u043e\u043f\u044b\u0442\u043e\u043a \u043e\u0431\u043e\u0439\u0442\u0438 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f GIL \u0438 \u0440\u0435\u0448\u0438\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u0434\u043b\u044f \u0440\u0430\u0437\u043d\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u0435\u0432.<\/p>\n<p>\u041f\u0435\u0440\u0432\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u2013 <code>threading<\/code> (\u0432 \u0440\u0435\u0436\u0438\u043c\u0435 \u0441 GIL \u043f\u043e-\u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e), \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u0435\u0441\u043b\u0438 \u0432\u044b \u0432\u044b\u0437\u044b\u0432\u0430\u043b\u0438 \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u0431\u0438\u043d\u0430\u0440\u043d\u044b\u0439 \u043a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0447\u0435\u0440\u0435\u0437 C-API \u043e\u0442\u043f\u0443\u0441\u043a\u0430\u043b GIL. \u041a\u0430\u043a <a href=\"https:\/\/t.me\/opensource_findings\/887\" rel=\"noopener noreferrer nofollow\">\u043c\u043e\u0436\u043d\u043e \u043e\u0442\u043f\u0443\u0441\u0442\u0438\u0442\u044c GIL<\/a>? <\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <a href=\"https:\/\/github.com\/python\/cpython\/blob\/5bbf30e89e7e1cb0a2b9bed9e0e99be291becbd3\/Modules\/mmapmodule.c#L1688-L1690\" rel=\"noopener noreferrer nofollow\">\u043c\u043e\u0434\u0443\u043b\u044c mmap \u0434\u0435\u043b\u0430\u0435\u0442 \u0442\u0430\u043a<\/a>:<\/p>\n<pre><code class=\"cpp\">Py_BEGIN_ALLOW_THREADS m_obj-&gt;data = mmap(NULL, map_size, prot, flags, fd, offset); Py_END_ALLOW_THREADS<\/code><\/pre>\n<p>\u0422\u0430\u043a \u043a\u0430\u043a \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0435 C-API \u0434\u043b\u044f \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f <code>PyThreadState<\/code>, \u043b\u044e\u0431\u043e\u0439 \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c <a href=\"https:\/\/docs.python.org\/3\/c-api\/init.html#c.Py_BEGIN_ALLOW_THREADS\" rel=\"noopener noreferrer nofollow\">\u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438<\/a> \u0438 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u0431\u044b\u0441\u0442\u0440\u0435\u0435. \u041d\u043e \u0442\u0430\u043a \u0434\u0435\u043b\u0430\u044e\u0442 \u043d\u0435 \u0432\u0441\u0435. \u0410 \u0435\u0449\u0435 \u0442\u0430\u043a \u043d\u0435\u043b\u044c\u0437\u044f \u0434\u0435\u043b\u0430\u0442\u044c \u0432 Python \u043a\u043e\u0434\u0435. \u041e\u0442\u0442\u043e\u0433\u043e <code>threading<\/code> \u0432 CPython \u0438\u043c\u0435\u043b \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043d\u0443\u044e \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0441\u0442\u044c. \u0411\u043e\u043b\u0435\u0435 \u0442\u043e\u0433\u043e: \u0442\u0440\u0435\u0434\u044b \u0442\u0440\u0435\u0431\u0443\u044e\u0442 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u043e\u0432 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u043b\u044f \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0434\u0430\u043d\u043d\u044b\u043c.<\/p>\n<p>\u041f\u043e\u0442\u043e\u043c\u0443 \u043f\u043e\u044f\u0432\u0438\u043b\u0441\u044f \u0432\u0442\u043e\u0440\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u2013 <code>multiprocessing<\/code>. \u041a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u0436\u0435 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u043b \u043d\u043e\u0432\u044b\u0435 \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u044b\u0435 Python \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u044b \u0441\u043e \u0441\u0432\u043e\u0435\u0439 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u044c\u044e. \u0414\u0430, \u043c\u043e\u0436\u043d\u043e <a href=\"https:\/\/docs.python.org\/3\/library\/multiprocessing.shared_memory.html#multiprocessing.shared_memory.SharedMemory\" rel=\"noopener noreferrer nofollow\">\u043a\u043e\u0435-\u0447\u0442\u043e \u0448\u0430\u0440\u0438\u0442\u044c<\/a>. \u041d\u043e \u0432\u0441\u0435 \u0440\u0430\u0432\u043d\u043e \u0437\u0430\u0442\u0440\u0430\u0442\u044b \u043d\u0430 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043d\u043e\u0432\u043e\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u0438 <code>*N<\/code> \u043f\u043e\u0442\u0440\u0435\u0431\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u2013 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 \u0432\u0430\u0448 \u0434\u0430\u0442\u0430\u0441\u0435\u0442 \u0438 \u0442\u0430\u043a \u0432\u0435\u0441\u0438\u0442 2\u0413\u0411, \u0435\u0433\u043e \u043e\u0447\u0435\u043d\u044c \u0441\u043b\u043e\u0436\u043d\u043e \u0432\u0437\u044f\u0442\u044c \u0438 \u043f\u0440\u043e\u0434\u0443\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432 \u0441\u043e\u0441\u0435\u0434\u043d\u0438\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043d\u0430 \u0435\u0449\u0435 +2\u0413\u0411. <\/p>\n<p>\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u2013 asyncio. \u041a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043b \u043e\u0442 \u043d\u0430\u0441 \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c \u0432\u0435\u0441\u044c \u043f\u0438\u0442\u043e\u043d, \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 <a href=\"https:\/\/journal.stuffwithstuff.com\/2015\/02\/01\/what-color-is-your-function\/\" rel=\"noopener noreferrer nofollow\">\u0446\u0432\u0435\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0439<\/a>, \u043d\u043e \u043d\u0435 \u0440\u0435\u0448\u0438\u043b \u0444\u0443\u043d\u0434\u0430\u043c\u0435\u043d\u0442\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u043e\u0431\u043b\u0435\u043c. \u041e\u043d \u0432\u0441\u0435 \u0435\u0449\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u043b \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u043e\u0434\u043d\u043e\u0433\u043e GIL, \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u043e\u0434\u043d\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430, \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u043e\u0434\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430. \u041d\u0438\u043a\u0430\u043a \u043d\u0435 \u043f\u043e\u043c\u043e\u0433\u0430\u043b \u0441 CPU-bound \u0437\u0430\u0434\u0430\u0447\u0430\u043c\u0438. \u0424\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u043c \u0433\u0432\u043e\u0437\u0434\u0435\u043c \u0432 \u043a\u0440\u044b\u0448\u043a\u0443 \u0433\u0440\u043e\u0431\u0430 <code>asyncio<\/code> \u0441\u0442\u0430\u043b\u043e \u0442\u043e, \u0447\u0442\u043e \u043d\u0435 \u0431\u044b\u043b\u043e \u043f\u0440\u043e\u0434\u0443\u043c\u0430\u043d\u043e, \u043a\u0430\u043a \u043e\u043d\u043e \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c. \u041e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u043f\u043e\u043d\u044f\u0442\u043d\u044b\u0445 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u043e\u0432, \u044f\u0432\u043d\u044b\u0445 cancelation-scopes, \u0438\u043d\u0442\u0440\u043e\u0441\u043f\u0435\u043a\u0446\u0438\u0438 (<a href=\"https:\/\/t.me\/opensource_findings\/882\" rel=\"noopener noreferrer nofollow\">\u0434\u043e\u0431\u0430\u0432\u044f\u0442 \u0432 3.14<\/a>). \u0418 \u0435\u0449\u0435 \u043d\u0435\u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c, \u043c\u043d\u043e\u0433\u043e \u043f\u043b\u043e\u0445\u0438\u0445 \u0410\u041f\u0418, \u0434\u043e\u0441\u044f\u0433\u0430\u0435\u043c\u044b\u0435 \u043f\u0440\u0435\u0434\u0435\u043b\u044b \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u0441\u043b\u043e\u0436\u043d\u0430\u044f \u043c\u0435\u043d\u0442\u0430\u043b\u044c\u043d\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c, \u043f\u043b\u043e\u0445\u0430\u044f \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044f \u0441 \u043f\u043e\u0442\u043e\u043a\u0430\u043c\u0438, \u0438 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0441 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u0430\u043c\u0438 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438.<\/p>\n<p>\u041f\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u0435 free-threading \u043d\u0435 \u0441\u0442\u0430\u043b\u043e \u043d\u0435\u043e\u0436\u0438\u0434\u0430\u043d\u043d\u043e\u0441\u0442\u044c\u044e. \u041f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0442\u0440\u0435\u0434\u044b \u0434\u0435\u0448\u0435\u0432\u044b \u0432 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438, \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u044e\u0442 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 (\u0447\u0442\u043e, \u0441 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442\u044c \u043a \u043c\u0443\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u043e\u043c\u0443 \u0434\u043e\u0441\u0442\u0443\u043f\u0443, \u0433\u043e\u043d\u043a\u0430\u043c, \u0434\u0435\u0434\u043b\u043e\u043a\u0430\u043c \u0438 \u043f\u0440\u043e\u0447\u0435\u043c\u0443 \u0432\u0435\u0441\u0435\u043b\u044c\u044e \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438). \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u043a\u043b\u044e\u0447\u0430\u0442\u044c GIL \u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c <em>\u043d\u0430\u043a\u043b\u0430\u0434\u043d\u044b\u0435 \u0440\u0430\u0441\u0445\u043e\u0434\u044b \u043d\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442<\/em> \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 free-threading. \u0410 \u0442\u0430\u043a \u0436\u0435 \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u043e\u0431\u043c\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0441\u0432\u043e\u0439 \u043a\u043e\u0434 <code>threading.Lock<\/code> \u0438 \u043f\u0440\u043e\u0447\u0438\u043c\u0438 \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u0430\u043c\u0438. \u041d\u043e \u0432\u0441\u0435 \u0440\u0430\u0432\u043d\u043e \u0431\u0443\u0434\u0443\u0442 \u043c\u0435\u0441\u0442\u0430, \u0434\u0430\u0436\u0435 \u043f\u0440\u044f\u043c\u043e \u0432 <code>builtins<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435\u043b\u044c\u0437\u044f \u0444\u0438\u0437\u0438\u0447\u0435\u0441\u043a\u0438 \u0441\u043f\u0440\u044f\u0442\u0430\u0442\u044c \u043f\u043e\u0434 \u043e\u0434\u043d\u0443 \u043a\u0440\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0441\u0435\u043a\u0446\u0438\u044e (\u043c\u044c\u044e\u0442\u0435\u043a\u0441). \u0427\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0433\u043e\u043d\u043a\u0438 \u0431\u0443\u0434\u0443\u0442 \u0434\u0430\u0436\u0435 \u0432 \u0431\u0438\u043b\u0442\u0438\u043d\u0430\u0445. <a href=\"https:\/\/github.com\/python\/cpython\/issues\/120496\" rel=\"noopener noreferrer nofollow\">\u041f\u0440\u0438\u043c\u0435\u0440<\/a>: \u043e\u0431\u044b\u0447\u043d\u044b\u0435 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440\u044b \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 <code>--disable-gil<\/code>:<\/p>\n<pre><code class=\"python\">import concurrent.futures  N = 10000 for _ in range(100):     it = iter(range(N))     with concurrent.futures.ThreadPoolExecutor() as executor:         data = set(executor.map(lambda _: next(it), range(N)))         assert len(data) == N, f\"Expected {N} distinct elements, got {len(data)}\"  # Traceback (most recent call last): # File \"&lt;python-input-0&gt;\", line 8, in &lt;module&gt; #   assert len(data) == N, f\"Expected {N} distinct elements, got {len(data)}\" #          ^^^^^^^^^^^^^^ # AssertionError: Expected 10000 distinct elements, got 9999<\/code><\/pre>\n<p> \u0421\u0442\u0440\u0435\u043b\u044f\u0435\u043c \u0441\u0435\u0431\u0435 \u0432 \u043d\u043e\u0433\u0438 \u0441 N \u0440\u0443\u043a!<\/p>\n<p>\u0422\u0430\u043a \u0447\u0442\u043e \u2013 \u0441\u0443\u0431\u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440\u044b \u0432\u044b\u0433\u043b\u044f\u0434\u044f\u0442 \u043e\u0447\u0435\u043d\u044c \u0445\u043e\u0440\u043e\u0448\u0438\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u0435\u043c. \u041e\u043d\u0438 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0434\u0435\u0448\u0435\u0432\u044b \u0432 \u0437\u0430\u043f\u0443\u0441\u043a\u0435 (\u043d\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0435\u0449\u0435 \u0431\u044b\u0441\u0442\u0440\u0435\u0435 \u0438 \u043b\u0443\u0447\u0448\u0435 \u0432 \u0431\u0443\u0434\u0443\u0449\u0435\u043c, \u043e \u0447\u0435\u043c \u0435\u0441\u0442\u044c \u0432 \u0432\u0438\u0434\u0435\u043e), \u043a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u043d\u0438\u0445 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441\u043e \u0441\u0432\u043e\u0438\u043c GIL, \u0432\u043d\u0443\u0442\u0440\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u043d\u0435\u0442 \u043b\u043e\u043a\u043e\u0432 \u0438 \u043c\u0443\u0442\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445, \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0434\u043b\u044f CPU \u0438 IO bound \u0437\u0430\u0434\u0430\u0447, \u0435\u0441\u0442\u044c \u0448\u0430\u0440\u0438\u043d\u0433 \u0434\u0430\u043d\u043d\u044b\u0445 \u0431\u0435\u0437 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f (\u043a\u0430\u043a \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0435\u0440\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0438\u043c\u043c\u0443\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u044b\u0445 \u0438 <a href=\"https:\/\/peps.python.org\/pep-0683\" rel=\"noopener noreferrer nofollow\">immortal<\/a> \u0442\u0438\u043f\u043e\u0432, \u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a int, \u0442\u0430\u043a \u0438 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u0430\u044f \u043c\u0430\u0433\u0438\u044f \u0432\u043e\u043a\u0440\u0443\u0433 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f <code>memoryview<\/code>), \u0438 \u0431\u0443\u0434\u0435\u0442 \u0435\u0449\u0435 \u0431\u043e\u043b\u044c\u0448\u0435 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u0432 \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0438\u0445 \u0440\u0435\u043b\u0438\u0437\u0430\u0445.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u043c\u0430\u0433\u0438\u0438 \u0441 <code>memoryview<\/code> \u0438 \u043b\u044e\u0431\u044b\u043c\u0438 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u0431\u0430\u0444\u0435\u0440\u0430\u043c\u0438:<\/p>\n<pre><code class=\"python\">&gt;&gt;&gt; from concurrent import interpreters &gt;&gt;&gt; interp = interpreters.create() &gt;&gt;&gt; queue = interpreters.create_queue()  &gt;&gt;&gt; b = bytearray(b'123') &gt;&gt;&gt; m = memoryview(b) &gt;&gt;&gt; queue.put_nowait(m) &gt;&gt;&gt; interp.exec('(m := queue.get_nowait()); print(m); m[:] = b\"456\"')  # changing memory directly &lt;memory at 0x103274940&gt;  &gt;&gt;&gt; b  # was changed in another interpreter! bytearray(b'456')<\/code><\/pre>\n<p>\u0422\u0430\u043c \u043e\u0434\u0438\u043d \u0438 \u0442\u043e\u0442 \u0436\u0435 \u043e\u0431\u044a\u0435\u043a\u0442! \u041a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0435 \u0431\u044b\u043b\u043e. \u0427\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u043d\u0430\u043c \u0448\u0430\u0440\u0438\u0442\u044c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <code>np.array<\/code> \u0438\u043b\u0438 \u043b\u044e\u0431\u044b\u0435 \u0434\u0440\u0443\u0433\u0438\u0435 <a href=\"https:\/\/docs.python.org\/3\/c-api\/buffer.html\" rel=\"noopener noreferrer nofollow\">\u0431\u0430\u0444\u0435\u0440\u044b<\/a>. \u0412\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043e\u0447\u0435\u043d\u044c \u043f\u0435\u0440\u0441\u043f\u0435\u043a\u0442\u0438\u0432\u043d\u043e. \u041d\u0443 \u0438, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u0441\u0432\u0435\u0440\u0445\u0443 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u043a\u0440\u0443\u0442\u0438\u0442\u044c \u0438 \u043c\u043e\u0434\u0435\u043b\u044c \u0430\u043a\u0442\u043e\u0440\u043e\u0432 (\u043e \u0447\u0435\u043c \u0442\u043e\u0436\u0435 \u0433\u043e\u0432\u043e\u0440\u0438\u043c \u0432 \u0432\u0438\u0434\u0435\u043e), \u0438 <a href=\"https:\/\/github.com\/python\/cpython\/blob\/main\/Modules\/_interpchannelsmodule.c\" rel=\"noopener noreferrer nofollow\">CSP \u043a\u0430\u043a \u0432 Go<\/a>.<\/p>\n<h2>\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u0441\u0443\u0431\u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440\u044b?<\/h2>\n<p>\u0427\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c, \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u0441\u0443\u0431\u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440\u044b, \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043d\u044f\u0442\u044c \u2013 \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440 \u0432 CPython \ud83d\ude42<\/p>\n<p>\u041a\u043e\u0433\u0434\u0430 \u043c\u044b \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043d\u043e\u0432\u044b\u0439 <code>python<\/code> \u043f\u0440\u043e\u0446\u0435\u0441\u0441, \u043c\u044b \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043a\u043e\u0434 \u0438\u0437 \u0444\u0430\u0439\u043b\u0430 <a href=\"https:\/\/github.com\/python\/cpython\/blob\/main\/Python\/pylifecycle.c\" rel=\"noopener noreferrer nofollow\">pylifecycle.c<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043a\u0430\u043a \u0440\u0430\u0437 \u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440, \u0430 \u0442\u0430\u043a \u0436\u0435 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0432\u0441\u0435 \u0434\u0440\u0443\u0433\u0438\u0435 \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u0436\u0438\u0437\u043d\u0435\u043d\u043d\u043e\u0433\u043e \u0446\u0438\u043a\u043b\u0430. \u0422\u0430\u043c \u0435\u0441\u0442\u044c \u0432\u043e\u0442 \u0442\u0430\u043a\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f:<\/p>\n<pre><code class=\"cpp\">static PyStatus pycore_create_interpreter(_PyRuntimeState *runtime,                           const PyConfig *src_config,                           PyThreadState **tstate_p) {     PyStatus status;     PyInterpreterState *interp;     status = _PyInterpreterState_New(NULL, &amp;interp);     if (_PyStatus_EXCEPTION(status)) {         return status;     }     assert(interp != NULL);     assert(_Py_IsMainInterpreter(interp));     _PyInterpreterState_SetWhence(interp, _PyInterpreterState_WHENCE_RUNTIME);     interp-&gt;_ready = 1;      status = _PyConfig_Copy(&amp;interp-&gt;config, src_config);     if (_PyStatus_EXCEPTION(status)) {         return status;     }      \/* Auto-thread-state API *\/     status = _PyGILState_Init(interp);     if (_PyStatus_EXCEPTION(status)) {         return status;     }      \/\/ ...   }<\/code><\/pre>\n<p>\u041e\u043d\u0430 \u0441\u043e\u0437\u0434\u0430\u0441\u0442 \u0432\u0430\u043c \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u2013 \u0433\u043b\u0430\u0432\u043d\u044b\u0439 \u2013 \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440, \u0435\u0433\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435, GIL \u0438 \u0432\u0441\u0435 \u0434\u0440\u0443\u0433\u0438\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0434\u043b\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0432\u0435\u0449\u0438. \u0422\u0435\u043f\u0435\u0440\u044c \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u0435\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0442\u0435 \u0441\u0430\u043c\u044b\u0435 &#171;\u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f&#187;, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u043d\u0430 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \/ \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442. \u0418\u0445 \u0434\u0432\u0430 \u0433\u043b\u0430\u0432\u043d\u044b\u0445: <code>PyThreadState<\/code> (<a href=\"https:\/\/github.com\/python\/cpython\/blob\/f320c951c3220aa6727b581216463e8b3f8bcd6b\/Include\/cpython\/pystate.h#L66\" rel=\"noopener noreferrer nofollow\">\u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043f\u043e\u0442\u043e\u043a\u0430<\/a>) \u0438 <code>PyInterpreterState<\/code> (<a href=\"https:\/\/github.com\/python\/cpython\/blob\/main\/Include\/internal\/pycore_interp_structs.h#L767\" rel=\"noopener noreferrer nofollow\">\u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440\u0430<\/a>), \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043f\u0440\u0438\u0432\u044f\u0437\u0430\u043d\u043e \u043a \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044e \u043f\u043e\u0442\u043e\u043a\u0430. \u041d\u0443 \u0447\u0442\u043e \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u044e. \u0412\u043e\u0442 \u0434\u0435\u0444\u0438\u043d\u0438\u0446\u0438\u0438: <\/p>\n<pre><code class=\"cpp\">typedef struct _ts PyThreadState; typedef struct _is PyInterpreterState;  struct _ts {     \/* See Python\/ceval.c for comments explaining most fields *\/      PyThreadState *prev;     PyThreadState *next;     PyInterpreterState *interp;      \/* The global instrumentation version in high bits, plus flags indicating        when to break out of the interpreter loop in lower bits. See details in        pycore_ceval.h. *\/     uintptr_t eval_breaker;      \/* Currently holds the GIL. Must be its own field to avoid data races *\/     int holds_gil;      \/\/ ... };<\/code><\/pre>\n<p>\u0412\u043d\u0443\u0442\u0440\u0438 \u043c\u043e\u0436\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u043c\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0433\u043e \u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u043e\u0433\u043e. \u0412 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 <code>PyInterpreterState<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u0436\u0435 \u0432 \u0441\u0435\u0431\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0435\u0442 \u0431\u043e\u043b\u044c\u0448\u0435 \u043f\u0440\u0438\u043a\u043b\u0430\u0434\u043d\u044b\u0445 \u0432\u0435\u0449\u0435\u0439. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440: \u0441\u0432\u043e\u0438 <code>builtins<\/code> \u0438 <code>sys<\/code>, \u0441\u0432\u043e\u0438 \u0438\u043c\u043f\u043e\u0440\u0442\u044b, \u0441\u0432\u043e\u0439 GIL \u0432  <code>_gil<\/code> (\u0438\u043b\u0438 \u043e\u0431\u0449\u0438\u0439 \u0432 <code>ceval<\/code> \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 <code>PyInterpreterConfig_SHARED_GIL<\/code>, \u0441\u043c <a href=\"https:\/\/github.com\/python\/cpython\/blob\/180b3eb697bf5bb0088f3f35ef2d3675f9fff04f\/Python\/ceval_gil.c#L499\" rel=\"noopener noreferrer nofollow\">_PyEval_InitGIL<\/a>) \u0438 \u0432\u0441\u0435 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0435 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b:<\/p>\n<pre><code class=\"cpp\">struct _is {     struct _ceval_state ceval;        struct _gc_runtime_state gc;      \/\/ Dictionary of the sys module     PyObject *sysdict;      \/\/ Dictionary of the builtins module     PyObject *builtins;      struct _import_state imports;      \/* The per-interpreter GIL, which might not be used. *\/     struct _gil_runtime_state _gil;      \/* cross-interpreter data and utils *\/     _PyXI_state_t xi;      \/\/ ... };<\/code><\/pre>\n<p>\u0420\u0430\u0437\u043e\u0431\u0440\u0430\u043b\u0438\u0441\u044c: \u0432\u043e\u0442 \u0447\u0442\u043e \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u0442\u0430\u043a\u043e\u0435 &#171;\u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440&#187;. \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043f\u043e\u043d\u0438\u043c\u0430\u0435\u043c, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u0442\u0430\u043a\u0438\u0445 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0439 \u0431\u0443\u0434\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e, \u0442\u043e \u043c\u044b \u0441\u043c\u043e\u0436\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u0445 (\u043f\u043e\u0447\u0435\u043c\u0443 \u043e\u043d\u0438 \u0431\u0443\u0434\u0443\u0442 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u043c\u0438 &#8212; \u043c\u044b \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u0447\u0443\u0442\u044c \u043f\u043e\u0437\u0436\u0435) \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440\u043e\u0432. C-API \u0434\u043b\u044f \u0442\u0430\u043a\u043e\u0433\u043e \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e \u0443\u0436\u0435 \u0441 Python 3.10. \u0421\u043c\u043e\u0442\u0440\u0438\u043c: <a href=\"https:\/\/docs.python.org\/dev\/c-api\/init.html#sub-interpreter-support\" rel=\"noopener noreferrer nofollow\">https:\/\/docs.python.org\/dev\/c-api\/init.html#sub-interpreter-support<\/a><\/p>\n<pre><code class=\"cpp\">PyInterpreterConfig config = {     .use_main_obmalloc = 0,     .allow_fork = 0,     .allow_exec = 0,     .allow_threads = 1,     .allow_daemon_threads = 0,     .check_multi_interp_extensions = 1,     .gil = PyInterpreterConfig_OWN_GIL, };  PyThreadState *tstate = NULL;  \/\/ &lt;-  PyStatus status = Py_NewInterpreterFromConfig(&amp;tstate, &amp;config); if (PyStatus_Exception(status)) {     Py_ExitStatusException(status); }<\/code><\/pre>\n<p>\u0412 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0432\u044b\u0448\u0435 \u043c\u044b \u0442\u0430\u043a \u0436\u0435 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043d\u043e\u0432\u044b\u0435 <code>PyThreadState<\/code> \u0438 <code>PyInterpreterState<\/code>. \u0427\u0442\u043e \u0432 \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0435 \u0441 CPython \u043d\u0430 \u0440\u0443\u0441\u0441\u043a\u0438\u0439 \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442: \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043d\u043e\u0432\u044b\u0439 \u043f\u043e\u0442\u043e\u043a \u0438 \u043d\u043e\u0432\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440 \u0432\u043d\u0443\u0442\u0440\u0438 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430. \u0418 \u0432\u043e\u0442 \u0442\u0443\u0442 \u043a\u043b\u044e\u0447\u0435\u0432\u0430\u044f \u0440\u0430\u0437\u043d\u0438\u0446\u0430 \u0441 &#171;\u043f\u0440\u043e\u0441\u0442\u043e Python \u043f\u043e\u0442\u043e\u043a\u043e\u043c&#187;. \u0418\u0437-\u0437\u0430 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0437\u0434\u0435\u0441\u044c \u043c\u044b \u0432\u043e\u043b\u044c\u043d\u044b \u0432\u044b\u0431\u0438\u0440\u0430\u0442\u044c \u0442\u0438\u043f GIL (\u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 &#8212; \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c <a href=\"https:\/\/peps.python.org\/pep-0684\" rel=\"noopener noreferrer nofollow\">PEP-684 Per-Interpreter GIL<\/a>), \u0442\u043e \u043f\u043e\u0442\u043e\u043a\u0438 \u0431\u0443\u0434\u0443\u0442 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0448\u0435\u0434\u0443\u043b\u0435\u0440\u043e\u043c OS, \u0430 \u043d\u0435 \u043e\u0431\u044b\u0447\u043d\u043e\u0439 \u043b\u043e\u0433\u0438\u043a\u043e\u0439 GIL \u043f\u0438\u0442\u043e\u043d\u0430. \u0418 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u043f\u0430\u0440\u0430\u043b\u0435\u043b\u043b\u044c\u043d\u043e \u0438 \u0438\u0437\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043e!<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u043f\u043e\u043d\u044f\u0442\u044c: \u043f\u043e\u0447\u0435\u043c\u0443 \u043e\u043d\u043e \u0438\u0437\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043e? \u041a\u0430\u043a \u0438\u043d\u0442\u0435\u0440\u043f\u0435\u0440\u0442\u0430\u0442\u043e\u0440\u044b \u043d\u0435 \u043c\u0435\u0448\u0430\u044e\u0442 \u0434\u0440\u0443\u0433 \u0434\u0440\u0443\u0433\u0443? \u041a\u0430\u043a \u043e\u043d\u0438 \u0434\u043e\u0441\u0442\u0438\u0433\u0430\u044e\u0442 \u0438\u0437\u043e\u043b\u044f\u0446\u0438\u0438?<\/p>\n<h2>\u0418\u0437\u043e\u043b\u044f\u0446\u0438\u044f \u0441\u0443\u0431\u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440\u043e\u0432<\/h2>\n<p>\u0421\u0430\u043c\u044b\u0439 \u043f\u0440\u043e\u0441\u0442\u043e\u0439, \u043d\u043e \u0438 \u0441\u0430\u043c\u044b\u0439 \u0441\u043b\u043e\u0436\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442. \u0427\u0442\u043e\u0431\u044b \u0438\u0437\u043e\u043b\u044f\u0446\u0438\u044f \u0440\u0430\u0431\u043e\u0442\u0430\u043b\u0430, \u043d\u0430\u043c \u043f\u043e\u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043b\u043e\u0441\u044c \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c \u0412\u0421\u0415 \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0435 C-\u043c\u043e\u0434\u0443\u043b\u0438, \u0412\u0421\u0415 \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0435 C-\u043a\u043b\u0430\u0441\u0441\u044b \u043f\u0438\u0442\u043e\u043d\u0430. \u0413\u0438\u0433\u0430\u043d\u0442\u0441\u043a\u0438\u0439 \u043e\u0431\u044a\u0435\u043c \u0440\u0430\u0431\u043e\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0437\u0430\u0442\u0440\u0430\u0433\u0438\u0432\u0430\u043b \u0431\u0443\u043a\u0432\u0430\u043b\u044c\u043d\u043e \u0432\u0441\u044e \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0443\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443. \u041d\u0443 \u0438 \u0435\u0441\u043b\u0438 \u0430\u0432\u0442\u043e\u0440\u044b \u0434\u0440\u0443\u0433\u0438\u0445 C-extensions \u0445\u043e\u0442\u044f\u0442 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0442\u044c SubInterpreters (\u0438\u043b\u0438 Free-Threading, \u043a\u0441\u0442\u0430\u0442\u0438, \u0442\u043e\u0436\u0435), \u0438\u043c \u0442\u043e\u0436\u0435 \u043d\u0443\u0436\u043d\u043e \u0432\u0441\u0435 \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c \ud83c\udf1a\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f\ufe0f<\/p>\n<p>\u0414\u0430\u043d\u043d\u0430\u044f \u0438\u0437\u043e\u043b\u044f\u0446\u0438\u044f \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0430\u0441\u044c \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c \u0444\u0430\u043a\u0442\u043e\u0440\u0430\u043c:<\/p>\n<ul>\n<li>\n<p>\u0414\u0432\u0443\u0445\u0444\u0430\u0437\u043d\u043e\u0439 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043c\u043e\u0434\u0443\u043b\u0435\u0439: <a href=\"https:\/\/peps.python.org\/pep-0489\" rel=\"noopener noreferrer nofollow\">https:\/\/peps.python.org\/pep-0489<\/a><\/p>\n<\/li>\n<li>\n<p>\u0418\u0437\u043e\u043b\u044f\u0446\u0438\u0438 \u043c\u043e\u0434\u0443\u043b\u0435\u0439 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 ModuleState: <a href=\"https:\/\/peps.python.org\/pep-0687\" rel=\"noopener noreferrer nofollow\">https:\/\/peps.python.org\/pep-0687<\/a><\/p>\n<\/li>\n<li>\n<p>\u0420\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433\u0443 \u0441\u0442\u0430\u0442\u0438\u0447\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432 \u0432 Heap-Types: <a href=\"https:\/\/docs.python.org\/3.11\/howto\/isolating-extensions.html#heap-types\" rel=\"noopener noreferrer nofollow\">https:\/\/docs.python.org\/3.11\/howto\/isolating-extensions.html#heap-types<\/a><\/p>\n<\/li>\n<\/ul>\n<p>\u0420\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u0432\u0441\u0435 \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445. \u041d\u0430\u0447\u043d\u0435\u043c \u0441 PEP-489 \u2013 \u0434\u0432\u0443\u0445\u0444\u0430\u0437\u043d\u0430\u044f \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043c\u043e\u0434\u0443\u043b\u0435\u0439. \u0411\u0443\u0434\u0435\u043c \u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 <code>mmap<\/code> \u043a\u0430\u043a \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440. \u041a\u0430\u043a \u043e\u043d \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u043b \u0440\u0430\u043d\u044c\u0448\u0435? <\/p>\n<pre><code class=\"cpp\">static struct PyModuleDef mmapmodule = {  \/\/ !!!     PyModuleDef_HEAD_INIT,     \"mmap\",     NULL,     -1,     NULL,     NULL,     NULL,     NULL,     NULL };  PyMODINIT_FUNC PyInit_mmap(void) {     PyObject *dict, *module;      if (PyType_Ready(&amp;mmap_object_type) &lt; 0)         return NULL;      module = PyModule_Create(&amp;mmapmodule);     if (module == NULL)         return NULL;     dict = PyModule_GetDict(module);     if (!dict)         return NULL;     PyDict_SetItemString(dict, \"error\", PyExc_OSError);     PyDict_SetItemString(dict, \"mmap\", (PyObject*) &amp;mmap_object_type);      \/\/ ...      return module; }<\/code><\/pre>\n<p>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u043e\u0431\u0449\u0435\u0433\u043e \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u043c\u043e\u0434\u0443\u043b\u044f \u0432 <code>PyInit_mmap<\/code>? \u041d\u0430\u043c \u0442\u0430\u043a\u043e\u0435 \u043d\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442!<\/p>\n<p>\u0421\u0435\u0439\u0447\u0430\u0441 \u0435\u0433\u043e \u0434\u0435\u0444\u0438\u043d\u0438\u0446\u0438\u044f \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"cpp\">static int mmap_exec(PyObject *module) {     if (PyModule_AddObjectRef(module, \"error\", PyExc_OSError) &lt; 0) {         return -1;     }      PyObject *mmap_object_type = PyType_FromModuleAndSpec(module,                                                   &amp;mmap_object_spec, NULL);     if (mmap_object_type == NULL) {         return -1;     }     int rc = PyModule_AddType(module, (PyTypeObject *)mmap_object_type);     Py_DECREF(mmap_object_type);     if (rc &lt; 0) {         return -1;     }      \/\/ ...      return 0; }  static PyModuleDef_Slot mmap_slots[] = {     {Py_mod_exec, mmap_exec},     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},     {Py_mod_gil, Py_MOD_GIL_NOT_USED},     {0, NULL} };  static struct PyModuleDef mmapmodule = {     .m_base = PyModuleDef_HEAD_INIT,     .m_name = \"mmap\",     .m_size = 0,     .m_slots = mmap_slots, };  PyMODINIT_FUNC PyInit_mmap(void) {     return PyModuleDef_Init(&amp;mmapmodule); }<\/code><\/pre>\n<p>\u0427\u0442\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u043e\u0441\u044c?<\/p>\n<ol>\n<li>\n<p>\u041d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u0430\u0441\u044c \u0434\u0435\u0444\u0438\u043d\u0438\u0446\u0438\u044f <code>static struct PyModuleDef mmapmodule<\/code>, \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0442\u0430\u043c \u0421-\u0441\u043b\u043e\u0442\u044b \u0431\u0443\u0434\u0443\u0449\u0435\u0433\u043e \u043c\u043e\u0434\u0443\u043b\u044f. \u0421\u0430\u043c\u044b\u0439 \u0432\u0430\u0436\u043d\u044b\u0439 \u0434\u043b\u044f \u043d\u0430\u0441 <code>Py_mod_exec<\/code><\/p>\n<\/li>\n<li>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>mmap_exec<\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0443\u043a\u0430\u0437\u0430\u043d\u0430 \u043a\u0430\u043a \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u0441\u043b\u043e\u0442 <code>{Py_mod_exec, mmap_exec}<\/code>, \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 \u0443\u0436\u0435 \u043a\u0435\u043c-\u0442\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u0434\u0443\u043b\u044c, \u043c\u044b \u0435\u0433\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0442\u0430\u043c \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c. \u0420\u0430\u043d\u0435\u0435 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u043b\u0438 <code>PyObject *<\/code> \u043c\u043e\u0434\u0443\u043b\u044f \u043f\u0440\u044f\u043c\u043e \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>PyInit_mmap<\/code> \u0438\u0437 \u0435\u0433\u043e \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 <code>module = PyModule_Create(&amp;mmapmodule)<\/code>. \u0427\u0442\u043e \u0431\u044b\u043b\u043e \u043d\u0435 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u0435\u043c\u043e \u0434\u043b\u044f \u043d\u043e\u0432\u044b\u0445 \u043a\u043e\u043f\u0438\u0439. \u0418\u043c\u0435\u043d\u043d\u043e \u043d\u043e\u0432\u044b\u0439 \u0410\u041f\u0418 \u0441 exec \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u0430\u043c \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c <strong>\u043d\u043e\u0432\u0443\u044e \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u0443\u044e \u043a\u043e\u043f\u0438\u044e \u043c\u043e\u0434\u0443\u043b\u044f<\/strong> \u043f\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0443.  <\/p>\n<\/li>\n<li>\n<p><code>PyType_Ready<\/code> \u0432 \u0442\u0435\u043b\u0435 \u043c\u043e\u0434\u0443\u043b\u044f \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 <code>mmap_object_spec<\/code> \u0442\u043e\u0436\u0435 \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u043e\u0441\u044c, \u0447\u0442\u043e \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u0442\u0441\u044f \u043d\u0430\u043c \u0432 \u0441\u0435\u043a\u0446\u0438\u0438 \u043f\u0440\u043e Heap Types<\/p>\n<\/li>\n<\/ol>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f <code>PyInit_mmap(void)<\/code> \u043e\u0441\u0442\u0430\u043b\u0430\u0441\u044c \u0434\u043b\u044f, \u0441\u043a\u043e\u0440\u0435\u0435, \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432 \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u0439 \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u0438 \u0438 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u043e\u0432. \u0422\u0435\u043f\u0435\u0440\u044c \u0442\u0430\u043c \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f <a href=\"https:\/\/github.com\/python\/cpython\/blob\/180b3eb697bf5bb0088f3f35ef2d3675f9fff04f\/Objects\/moduleobject.c#L52-L62\" rel=\"noopener noreferrer nofollow\">PyModuleDef_Init<\/a>.<\/p>\n<p>\u041a\u043e\u043c\u043c\u0438\u0442 \u043d\u0430 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f: <a href=\"https:\/\/github.com\/python\/cpython\/commit\/3ad52e366fea37b02a3f619e6b7cffa7dfbdfa2e\" rel=\"noopener noreferrer nofollow\">https:\/\/github.com\/python\/cpython\/commit\/3ad52e366fea37b02a3f619e6b7cffa7dfbdfa2e<\/a><\/p>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u043c\u044b \u044f\u0432\u043d\u043e \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0432 \u0441\u043b\u043e\u0442\u0430\u0445, \u0447\u0442\u043e \u0441\u0443\u0431\u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440\u044b \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0442\u0441\u044f: <code>{Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED}<\/code>. \u0415\u0441\u043b\u0438 \u0431\u044b \u043c\u044b \u043f\u043e\u043f\u044b\u0442\u0430\u043b\u0438\u0441\u044c \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043c\u043e\u0434\u0443\u043b\u044c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u044f\u0432\u043d\u043e, \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0431\u044b \u043e\u0448\u0438\u0431\u043a\u0443: <\/p>\n<pre><code class=\"python\">&gt;&gt;&gt; from concurrent.interpreters import create  &gt;&gt;&gt; interp = create() &gt;&gt;&gt; interp.exec('import _suggestions') Traceback (most recent call last):   File \"&lt;python-input-3&gt;\", line 1, in &lt;module&gt;     interp.exec('import _suggestions')     ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^   File \"\/Users\/sobolev\/Desktop\/cpython\/Lib\/concurrent\/interpreters\/__init__.py\", line 212, in exec     raise ExecutionFailed(excinfo) concurrent.interpreters.ExecutionFailed: ImportError: module _suggestions does not support loading in subinterpreters  Uncaught in the interpreter:  Traceback (most recent call last):   File \"&lt;script&gt;\", line 1, in &lt;module&gt; ImportError: module _suggestions does not support loading in subinterpreters<\/code><\/pre>\n<p>\u0412\u0442\u043e\u0440\u0430\u044f \u0447\u0430\u0441\u0442\u044c: \u0438\u0437\u043e\u043b\u044f\u0446\u0438\u044f \u0441\u0442\u0435\u0439\u0442\u0430 \u043c\u043e\u0434\u0443\u043b\u044f. \u0423\u0431\u0438\u0440\u0430\u0435\u043c \u0432\u0441\u0435 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0432 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0435 \u043c\u0435\u0441\u0442\u043e. \u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043c\u043e\u0434\u0443\u043b\u044f <code>_csv<\/code>. \u0412\u043e\u0442 \u0442\u0430\u043a \u0431\u044b\u043b\u043e \u0440\u0430\u043d\u044c\u0448\u0435:<\/p>\n<pre><code class=\"cpp\">static PyObject *error_obj;     \/* CSV exception *\/ static PyObject *dialects;      \/* Dialect registry *\/ static long field_limit = 128 * 1024;   \/* max parsed field size *\/ static PyTypeObject Dialect_Type; \/\/ ...<\/code><\/pre>\n<p>\u0412\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u043e. \u041d\u0438\u043a\u0430\u043a\u0438\u0445 \u0442\u0435\u0431\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0410\u041f\u0418. \u041d\u043e \u0442\u0443\u0442 \u0432\u0441\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435. \u0410 \u043d\u0430\u043c \u0442\u0430\u043a\u043e\u0435 \u2013 \u043d\u0435\u043b\u044c\u0437\u044f!<\/p>\n<p>\u0412\u043e\u0442 \u0442\u0430\u043a \u0441\u0442\u0430\u043b\u043e \u0441\u0435\u0439\u0447\u0430\u0441, \u0447\u0430\u0441\u0442\u044c \u043f\u0435\u0440\u0432\u0430\u044f:<\/p>\n<pre><code class=\"cpp\">typedef struct {     PyObject *error_obj;   \/* CSV exception *\/     PyObject *dialects;   \/* Dialect registry *\/     PyTypeObject *dialect_type;     PyTypeObject *reader_type;     PyTypeObject *writer_type;     Py_ssize_t field_limit;   \/* max parsed field size *\/     PyObject *str_write; } _csvstate;  static struct PyModuleDef _csvmodule;  static inline _csvstate* get_csv_state(PyObject *module) {     void *state = PyModule_GetState(module);     assert(state != NULL);     return (_csvstate *)state; }  static int _csv_clear(PyObject *module) {     _csvstate *module_state = PyModule_GetState(module);     Py_CLEAR(module_state-&gt;error_obj);     Py_CLEAR(module_state-&gt;dialects);     Py_CLEAR(module_state-&gt;dialect_type);     Py_CLEAR(module_state-&gt;reader_type);     Py_CLEAR(module_state-&gt;writer_type);     Py_CLEAR(module_state-&gt;str_write);     return 0; }  static int _csv_traverse(PyObject *module, visitproc visit, void *arg) {     _csvstate *module_state = PyModule_GetState(module);     Py_VISIT(module_state-&gt;error_obj);     Py_VISIT(module_state-&gt;dialects);     Py_VISIT(module_state-&gt;dialect_type);     Py_VISIT(module_state-&gt;reader_type);     Py_VISIT(module_state-&gt;writer_type);     return 0; }  static void _csv_free(void *module) {     (void)_csv_clear((PyObject *)module); }<\/code><\/pre>\n<p>\u0422\u0443\u0442 \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0441\u0430\u043c \u0441\u0442\u0435\u0439\u0442 <code>_csvstate<\/code>, \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c, \u043a\u0430\u043a \u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c <code>get_csv_state<\/code>, \u043a\u0430\u043a \u0435\u0433\u043e \u043e\u0447\u0438\u0441\u0442\u0438\u0442\u044c <code>_csv_clear<\/code>, \u043a\u0430\u043a \u0435\u0433\u043e \u043e\u0431\u0445\u043e\u0434\u0438\u0442\u044c \u0432 GC <code>_csv_traverse<\/code>. \u0412\u0442\u043e\u0440\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u0441\u0432\u044f\u0437\u0430\u043d\u0430 \u0441\u043e \u0441\u043b\u043e\u0442\u0430\u043c\u0438 \u043c\u043e\u0434\u0443\u043b\u044f, \u0440\u0430\u0437\u043c\u0435\u0440\u0430\u043c\u0438 \u0441\u0442\u0435\u0439\u0442\u0430 \u0438 \u0435\u0433\u043e <a href=\"https:\/\/github.com\/python\/cpython\/blob\/cb59eaefeda5ff44ac0c742bff2b8afc023be313\/Modules\/_csv.c#L1755\" rel=\"noopener noreferrer nofollow\">\u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435\u043c<\/a>:<\/p>\n<pre><code class=\"cpp\">static struct PyModuleDef _csvmodule = {     PyModuleDef_HEAD_INIT,     \"_csv\",     csv_module_doc,     sizeof(_csvstate), \/\/ !!! \u0440\u0430\u0437\u043c\u0435\u0440 \u0441\u0442\u0435\u0439\u0442\u0430     csv_methods,     csv_slots,     _csv_traverse,  \/\/ Py_tp_traverse     _csv_clear,  \/\/ Py_tp_clear     _csv_free  \/\/ Py_tp_free };  static int csv_exec(PyObject *module) {     PyObject *temp;     _csvstate *module_state = get_csv_state(module);      temp = PyType_FromModuleAndSpec(module, &amp;Dialect_Type_spec, NULL);     \/\/ \u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0441\u0442\u0435\u0439\u0442\u0430 \u0442\u0443\u0442:     module_state-&gt;dialect_type = (PyTypeObject *)temp;     if (PyModule_AddObjectRef(module, \"Dialect\", temp) &lt; 0) {         return -1;     }      \/\/ ... }<\/code><\/pre>\n<p>\u0421\u0430\u043c\u0430\u044f \u0432\u0430\u0436\u043d\u0430\u044f \u0441\u0442\u0440\u043e\u0447\u043a\u0430 \u0442\u0443\u0442: <code>sizeof(_csvstate)<\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043d\u0443\u0436\u043d\u043e \u043f\u0430\u043c\u044f\u0442\u0438 \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0441\u0442\u0435\u0439\u0442\u0430 \u043c\u043e\u0434\u0443\u043b\u044f \u0432\u043d\u0443\u0442\u0440\u0438 \u0441\u0430\u043c\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043c\u043e\u0434\u0443\u043b\u044f.<\/p>\n<p>\u041a\u043e\u043c\u043c\u0438\u0442 \u043d\u0430 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435: <a href=\"https:\/\/github.com\/python\/cpython\/commit\/6a02b384751dbc13979efc1185f0a7c1670dc349\" rel=\"noopener noreferrer nofollow\">https:\/\/github.com\/python\/cpython\/commit\/6a02b384751dbc13979efc1185f0a7c1670dc349<\/a> \u0438 <a href=\"https:\/\/github.com\/python\/cpython\/commit\/e7672d38dc430036539a2b1a279757d1cc819af7\" rel=\"noopener noreferrer nofollow\">https:\/\/github.com\/python\/cpython\/commit\/e7672d38dc430036539a2b1a279757d1cc819af7<\/a><\/p>\n<p>\u041a\u0430\u043a \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u2013 \u043a\u0430\u0436\u0434\u044b\u0439 \u043c\u043e\u0434\u0443\u043b\u044c \u0438\u043c\u0435\u0435\u0442 <strong>\u0441\u0432\u043e\u0435 \u0438\u0437\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435<\/strong>. \u041f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u043d\u043e\u0432\u043e\u0439 \u043a\u043e\u043f\u0438\u0438 \u043c\u043e\u0434\u0443\u043b\u044f \u0434\u043b\u044f \u0441\u0443\u0431\u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440\u0430 \u2013 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u0435\u0433\u043e \u043d\u043e\u0432\u043e\u0435 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435.<\/p>\n<p>\u041d\u0443 \u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0435 \u2013 Heap Types. \u041d\u0430\u0448\u0430 \u0437\u0430\u0434\u0430\u0447\u0430 \u0441\u043d\u043e\u0432\u0430 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0438\u043f\u044b \u043d\u0435 \u043e\u0431\u0449\u0438\u043c\u0438, \u0430 \u043a\u043e\u043f\u0438\u0440\u0443\u0435\u043c\u044b\u043c\u0438. \u0423\u0431\u0438\u0440\u0430\u0435\u043c <code>static<\/code> \u0442\u0438\u043f\u044b \u0438 \u0434\u0435\u043b\u0430\u0435\u043c \u0438\u0445 \u0438\u0437\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c\u0438. \u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u043c \u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 \u043c\u043e\u0434\u0443\u043b\u044c <code>_csv<\/code>, \u0431\u044b\u043b\u043e:<\/p>\n<pre><code class=\"cpp\">static PyTypeObject Dialect_Type = {     PyVarObject_HEAD_INIT(NULL, 0)     \"_csv.Dialect\",                         \/* tp_name *\/     sizeof(DialectObj),                     \/* tp_basicsize *\/     0,                                      \/* tp_itemsize *\/     \/*  methods  *\/     (destructor)Dialect_dealloc,            \/* tp_dealloc *\/     0,                                      \/* tp_vectorcall_offset *\/     (getattrfunc)0,                         \/* tp_getattr *\/     (setattrfunc)0,                         \/* tp_setattr *\/     0,                                      \/* tp_as_async *\/     (reprfunc)0,                            \/* tp_repr *\/     0,                                      \/* tp_as_number *\/     0,                                      \/* tp_as_sequence *\/     0,                                      \/* tp_as_mapping *\/     (hashfunc)0,                            \/* tp_hash *\/     (ternaryfunc)0,                         \/* tp_call *\/     (reprfunc)0,                                \/* tp_str *\/     0,                                      \/* tp_getattro *\/     0,                                      \/* tp_setattro *\/     0,                                      \/* tp_as_buffer *\/     Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, \/* tp_flags *\/     Dialect_Type_doc,                       \/* tp_doc *\/     0,                                      \/* tp_traverse *\/     0,                                      \/* tp_clear *\/     0,                                      \/* tp_richcompare *\/     0,                                      \/* tp_weaklistoffset *\/     0,                                      \/* tp_iter *\/     0,                                      \/* tp_iternext *\/     0,                                          \/* tp_methods *\/     Dialect_memberlist,                     \/* tp_members *\/     Dialect_getsetlist,                     \/* tp_getset *\/     0,                                          \/* tp_base *\/     0,                                          \/* tp_dict *\/     0,                                          \/* tp_descr_get *\/     0,                                          \/* tp_descr_set *\/     0,                                          \/* tp_dictoffset *\/     0,                                          \/* tp_init *\/     0,                                          \/* tp_alloc *\/     dialect_new,                                \/* tp_new *\/     0,                                          \/* tp_free *\/ };<\/code><\/pre>\n<p>\u041e\u0434\u0438\u043d \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442! \u0423\u0436\u0430\u0441!<\/p>\n<p>\u0421\u0442\u0430\u043b\u043e:<\/p>\n<pre><code class=\"cpp\">static PyType_Slot Dialect_Type_slots[] = {     {Py_tp_doc, (char*)Dialect_Type_doc},     {Py_tp_members, Dialect_memberlist},     {Py_tp_getset, Dialect_getsetlist},     {Py_tp_new, dialect_new},     {Py_tp_methods, dialect_methods},     {Py_tp_dealloc, Dialect_dealloc},     {Py_tp_clear, Dialect_clear},     {Py_tp_traverse, Dialect_traverse},     {0, NULL} };  PyType_Spec Dialect_Type_spec = {     .name = \"_csv.Dialect\",     .basicsize = sizeof(DialectObj),     .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC |               Py_TPFLAGS_IMMUTABLETYPE),     .slots = Dialect_Type_slots, };  static int csv_exec(PyObject *module) {     PyObject *temp;     _csvstate *module_state = get_csv_state(module);      \/\/ Creating a real type from spec:     temp = PyType_FromModuleAndSpec(module, &amp;Dialect_Type_spec, NULL);     module_state-&gt;dialect_type = (PyTypeObject *)temp;     if (PyModule_AddObjectRef(module, \"Dialect\", temp) &lt; 0) {         return -1;     }     \/\/ ... }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c, \u0432\u043c\u0435\u0441\u0442\u043e \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f, \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0442\u0438\u043f \u0438\u0437 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u0432\u043d\u0443\u0442\u0440\u0438 <code>Py_mod_exec<\/code> \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 <code>PyType_FromModuleAndSpec<\/code>, \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0442\u0438\u043f \u0432 \u0441\u0442\u0435\u0439\u0442 \u043c\u043e\u0434\u0443\u043b\u044f \u0432 <code>module_state-&gt;dialect_type<\/code>. \u0418 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0443\u0436\u0435 \u0435\u0433\u043e, \u0433\u0434\u0435 \u043d\u0443\u0436\u043d\u043e. \u0417\u0430 \u0441\u0447\u0435\u0442 \u0447\u0435\u0433\u043e \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043f\u043e\u043b\u043d\u0443\u044e \u0438\u0437\u043e\u043b\u044f\u0446\u0438\u044e \u2013 \u043a\u0430\u0436\u0434\u044b\u0439 \u0441\u0443\u0431\u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440 \u0431\u0443\u0434\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0441\u0432\u043e\u0438 \u043c\u043e\u0434\u0443\u043b\u0438 \u0438 \u0441\u0432\u043e\u0438 \u0442\u0438\u043f\u044b. \u0423\u0434\u043e\u0431\u043d\u043e!<\/p>\n<h2>\u041a \u0437\u0430\u043c\u0435\u0440\u0430\u043c!<\/h2>\n<p>\u041a\u0430\u043a\u0430\u044f \u0436\u0435 \u0441\u0442\u0430\u0442\u044c\u044f \u0431\u0435\u0437 <strong>\u0441\u0438\u043d\u0442\u0435\u043d\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a\u043e\u0432<\/strong> \u0441 \u043e\u0448\u0438\u0431\u043a\u0430\u043c\u0438 \u0438 \u043d\u0435\u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044f\u043c\u0438? \u0412\u043e\u0442 \u0438 \u044f \u0442\u0430\u043a \u043f\u043e\u0434\u0443\u043c\u0430\u043b. \u041f\u0440\u0438\u0441\u0430\u0436\u0438\u0432\u0430\u0439\u0442\u0435\u0441\u044c \u043f\u043e\u0443\u0434\u043e\u0431\u043d\u0435\u0435, <a href=\"https:\/\/gist.github.com\/sobolevn\/149a461c629f6e03aef3a772c7422b2e\" rel=\"noopener noreferrer nofollow\">\u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u043a\u043e\u0434 \u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a\u043e\u0432<\/a>, \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0438\u0440\u0443\u0439\u0442\u0435. \u0412\u043e\u0442 \u0442\u0435\u0441\u0442 CPU-bound \u0437\u0430\u0434\u0430\u0447\u0438 \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c\u0438:<\/p>\n<pre><code class=\"python\">def worker_cpu(arg: tuple[int, int]):     start, end = arg     fact = 1     for i in range(start, end + 1):         fact *= i<\/code><\/pre>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c:<\/p>\n<pre><code class=\"1c\">Regular: Mean +- std dev: 163 ms +- 1 ms Threading with GIL: Mean +- std dev: 168 ms +- 2 ms Threading NoGIL: Mean +- std dev: 48.7 ms +- 0.6 ms Multiprocessing: Mean +- std dev: 73.4 ms +- 1.5 ms Subinterpreters: Mean +- std dev: 44.8 ms +- 0.5 ms<\/code><\/pre>\n<p>\u0421\u0443\u0431\u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440\u044b \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442 \u043b\u0443\u0447\u0448\u0435\u0435 \u0432\u0440\u0435\u043c\u044f! \u0412\u043e\u0442 \u0442\u0430\u043a \u043c\u044b \u0438\u0445 \u0432\u044b\u0437\u044b\u0432\u0430\u043b\u0438:<\/p>\n<pre><code class=\"python\">import os from concurrent.futures import InterpreterPoolExecutor  WORKLOADS = [(1, 5), (6, 10), (11, 15), (16, 20)]  CPUS = os.cpu_count() or len(WORKLOADS)  def bench_subinterpreters():     with InterpreterPoolExecutor(CPUS) as executor:         list(executor.map(worker, WORKLOADS))<\/code><\/pre>\n<p>\u0418 \u0434\u043b\u044f IO-bound \u0437\u0430\u0434\u0430\u0447:<\/p>\n<pre><code class=\"python\">def worker_io(arg: tuple[int, int]):     start, end = arg     with httpx.Client() as client:         for i in range(start, end + 1):             client.get(f'http:\/\/jsonplaceholder.typicode.com\/posts\/{i}')<\/code><\/pre>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b:<\/p>\n<pre><code class=\"1c\">Regular: Mean +- std dev: 1.45 sec +- 0.03 sec Threading with GIL: Mean +- std dev: 384 ms +- 17 ms (~1\/4 \u043e\u0442 1.45s) Threading NoGIL: Mean +- std dev: 373 ms +- 20 ms Multiprocessing: Mean +- std dev: 687 ms +- 32 ms Subinterpreters: Mean +- std dev: 547 ms +- 13 ms<\/code><\/pre>\n<p>\u0422\u0443\u0442 \u2013 free-threading \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0431\u044b\u0441\u0442\u0440\u0435\u0435, \u043d\u043e \u0438 \u0441\u0443\u0431\u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440\u044b \u0434\u0430\u044e\u0442 \u043f\u043e\u0447\u0442\u0438 x3 \u0443\u0441\u043a\u043e\u0440\u0435\u043d\u0438\u0435 \u043e\u0442 \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f. \u041e\u0442\u0434\u0435\u043b\u044c\u043d\u043e \u0441\u0440\u0430\u0432\u043d\u0438\u043c \u0441 \u0432\u0435\u0440\u0441\u0438\u0435\u0439 \u0434\u043b\u044f asyncio:<\/p>\n<pre><code class=\"python\">async def bench_async():     start, end = 1, 20     async with httpx.AsyncClient() as client:         await asyncio.gather(*[             client.get(f'http:\/\/jsonplaceholder.typicode.com\/posts\/{i}')             for i in range(start, end + 1)         ])<\/code><\/pre>\n<p>\u041a\u043e\u0442\u043e\u0440\u0430\u044f, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0431\u0435\u0434\u0438\u0442\u0435\u043b\u0435\u043c \u0441 <code>166 ms +- 13 ms<\/code>. <\/p>\n<p>\u0415\u0449\u0435 \u0431\u044b\u043b\u043e \u0431\u044b \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0437\u0430\u043c\u0435\u0440\u044b \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0431\u0430\u0444\u0435\u0440\u0430\u043c\u0438. \u041a\u043e\u0434 \u0432\u043e\u0442 \u0442\u0430\u043a\u043e\u0439 (\u0443\u0436\u0430\u0441\u043d\u044b\u0439, \u043d\u0435\u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439, \u043d\u043e \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u044e\u0449\u0438\u0439 \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u0443\u044e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0448\u0430\u0440\u0438\u043d\u0433\u0430 \u0442\u0430\u043a\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445):<\/p>\n<pre><code class=\"python\">import random import numpy as np  data = np.array([  # PyBuffer     random.randint(1, 1024)     for _ in range(1_000_000_0) ], dtype=np.int32) mv = memoryview(data)   # TODO: multiprocessing can't pickle it  def worker_numpy(arg: tuple[Any, int, int]):     # VERY inefficient way of summing numpy array, just to illustate     # the potential possibility:     data, start, end = arg     sum(data[start:end])  worker = worker_numpy chunks_num = os.cpu_count() * 2 + 1 chunk_size = int(len(data) \/ num_workers) WORKLOADS = [     (mv, chunk_size * i, chunk_size * (i + 1))     for i, cpu in enumerate(range(chunks_num)) ]<\/code><\/pre>\n<p>\u0414\u0430, \u043c\u044b \u0432\u044b\u0431\u0440\u0430\u043b\u0438 \u0441\u0430\u043c\u044b\u0439 \u043f\u043b\u043e\u0445\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0441\u043b\u043e\u0436\u0435\u043d\u0438\u044f <code>nparray<\/code>, \u043d\u043e \u043d\u0430\u043c \u0432\u0430\u0436\u0435\u043d \u043d\u0435 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0441\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0430 \u0441\u0430\u043c\u0430 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0441\u043e\u0432\u0435\u0440\u0448\u0430\u0442\u044c \u043b\u044e\u0431\u044b\u0435 \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438: \u0448\u0435\u0440\u0438\u043d\u0433 \u0434\u0430\u043d\u043d\u044b\u0445, \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430. \u041c\u044b \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0447\u0430\u043d\u043a\u043e\u0432 \u0434\u043b\u044f \u0441\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0443\u0434\u043e\u0441\u0442\u043e\u0432\u0435\u0440\u0438\u0432\u0430\u0435\u043c\u0441\u044f, \u0447\u0442\u043e \u043e\u043d\u043e \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 <code>PyBuffer<\/code> \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b \u0447\u0435\u0440\u0435\u0437 <code>memoryview<\/code>, \u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u0447\u0438\u0442\u0430\u0442\u044c\u0441\u044f \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c\u0438. \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c:<\/p>\n<pre><code class=\"1c\">..................... Regular: Mean +- std dev: 109 ms +- 1 ms ..................... Threading: Mean +- std dev: 112 ms +- 1 ms Multiprocessing: DISQUALIFIED, my macbook exploded ..................... Subinterpreters: Mean +- std dev: 58.4 ms +- 3.1 ms<\/code><\/pre>\n<p>\u0427\u0442\u043e \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0439 \u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a? \u0427\u0442\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0431\u044b\u0441\u0442\u0440\u043e \u043f\u043e\u0448\u0430\u0440\u0438\u0442\u044c \u0431\u0430\u0444\u0435\u0440 \u0438 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441 \u043d\u0438\u043c \u043a\u0430\u043a\u0443\u044e-\u0442\u043e \u043b\u043e\u0433\u0438\u043a\u0443. \u0418 \u0434\u0430\u0436\u0435 \u0431\u0435\u0437 \u043a\u0430\u043a\u0438\u0445 \u043b\u0438\u0431\u043e \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0439 \u0438 \u0441\u043e \u0432\u0441\u0435\u043c\u0438 \u043d\u0430\u043a\u043b\u0430\u0434\u043d\u044b\u043c\u0438 \u0440\u0430\u0441\u0445\u043e\u0434\u0430\u043c\u0438 \u2013 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432 \u0434\u0432\u0430 \u0440\u0430\u0437\u0430 \u0431\u044b\u0441\u0442\u0440\u0435\u0435 \u0441\u0442\u043e\u043a\u0430. \u041e\u0441\u043e\u0431\u043e \u0437\u0430\u0431\u0430\u0432\u043d\u043e \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0442\u044c \u0441 <code>multiprocessing<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0447\u0443\u0442\u044c \u043d\u0435 \u0432\u0437\u043e\u0440\u0432\u0430\u043b \u043c\u043d\u0435 \u043d\u043e\u0443\u0442. \u0418 \u044f \u043d\u0435 \u0441\u043c\u043e\u0433 \u0434\u043e\u0436\u0434\u0430\u0442\u044c\u0441\u044f \u043a\u043e\u043d\u0446\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f. <\/p>\n<p>\u0415\u0441\u0442\u044c \u043b\u0438 \u0441\u043f\u043e\u0441\u043e\u0431 \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0441\u0443\u0431\u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440\u043e\u0432? \u041a\u043e\u043d\u0435\u0447\u043d\u043e! \u0421\u043a\u043e\u0440\u043e \u0443\u0432\u0438\u0434\u0438\u043c!<\/p>\n<h2>\u0417\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0435<\/h2>\n<p>\u0412\u043e\u0442 \u0442\u0430\u043a\u0430\u044f \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0430\u0441\u044c \u0444\u0438\u0447\u0430. \u041c\u043d\u043e\u0433\u043e\u0435 \u043c\u044b \u043d\u0435 \u0443\u0441\u043f\u0435\u043b\u0438 \u043e\u0431\u0441\u0443\u0434\u0438\u0442\u044c \u0432 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440: <a href=\"https:\/\/discuss.python.org\/c\/core-dev\/23\" rel=\"noopener noreferrer nofollow\">\u043d\u044e\u0430\u043d\u0441\u044b \u043f\u0435\u043f\u043e-\u043f\u0440\u0438\u043d\u044f\u0442\u0438\u044f<\/a>, Channels, Queues, <a href=\"https:\/\/docs.python.org\/3.14\/library\/concurrent.futures.html#concurrent.futures.InterpreterPoolExecutor\" rel=\"noopener noreferrer nofollow\">concurrent.futures.InterpreterPool<\/a> \u0438 \u0435\u0433\u043e \u0442\u0435\u043a\u0443\u0449\u0438\u0435 <a href=\"https:\/\/github.com\/python\/cpython\/issues\/136659\" rel=\"noopener noreferrer nofollow\">\u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b<\/a>. \u041e\u0434\u043d\u0430\u043a\u043e, \u043d\u0435\u043b\u044c\u0437\u044f \u0432\u043f\u0438\u0445\u043d\u0443\u0442\u044c \u0432 \u043e\u0434\u043d\u0443 \u0441\u0442\u0430\u0442\u044c\u044e \u0432\u0441\u0435, \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u043e\u0447\u0435\u043d\u044c \u0445\u043e\u0447\u0435\u0442\u0441\u044f. \u0422\u0430\u043a \u0447\u0442\u043e, \u043e\u0441\u0442\u0430\u0435\u043c\u0441\u044f \u043d\u0430 \u0441\u0432\u044f\u0437\u0438 \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0441\u0442\u0430\u0442\u044c\u044f\u0445!<\/p>\n<p>\u041c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u0434\u043b\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438:<\/p>\n<ul>\n<li>\n<p>\u041c\u043e\u0439 \u043f\u043e\u0441\u0442 \u043f\u0440\u043e \u0437\u0430\u043c\u0435\u0440 \u043f\u0435\u0440\u0444\u043e\u0440\u043c\u0430\u043d\u0441\u0430 \u0441\u0443\u0431\u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440\u043e\u0432: <a href=\"https:\/\/t.me\/opensource_findings\/916\" rel=\"noopener noreferrer nofollow\">https:\/\/t.me\/opensource_findings\/916<\/a> <\/p>\n<\/li>\n<li>\n<p>\u041c\u043e\u0439 \u043f\u043e\u0441\u0442 \u043f\u0440\u043e <code>concurrent.interpreters.Queue<\/code>: <a href=\"https:\/\/t.me\/opensource_findings\/918\" rel=\"noopener noreferrer nofollow\">https:\/\/t.me\/opensource_findings\/918<\/a><\/p>\n<\/li>\n<li>\n<p>Multiple Interpreters in the Stdlib: <a href=\"https:\/\/peps.python.org\/pep-0554\" rel=\"noopener noreferrer nofollow\">https:\/\/peps.python.org\/pep-0554<\/a><\/p>\n<\/li>\n<li>\n<p>Older PEP Multiple Interpreters in the Stdlib: <a href=\"https:\/\/peps.python.org\/pep-0734\" rel=\"noopener noreferrer nofollow\">https:\/\/peps.python.org\/pep-0734<\/a><\/p>\n<\/li>\n<li>\n<p>A Per-Interpreter GIL: <a href=\"https:\/\/peps.python.org\/pep-0684\" rel=\"noopener noreferrer nofollow\">https:\/\/peps.python.org\/pep-0684<\/a><\/p>\n<\/li>\n<li>\n<p>Multi-phase extension module initialization: <a href=\"https:\/\/peps.python.org\/pep-0489\" rel=\"noopener noreferrer nofollow\">https:\/\/peps.python.org\/pep-0489<\/a><\/p>\n<\/li>\n<li>\n<p>A ModuleSpec Type for the Import System: <a href=\"https:\/\/peps.python.org\/pep-0451\" rel=\"noopener noreferrer nofollow\">https:\/\/peps.python.org\/pep-0451<\/a><\/p>\n<\/li>\n<li>\n<p>Isolating modules in the standard library: <a href=\"https:\/\/peps.python.org\/pep-0687\" rel=\"noopener noreferrer nofollow\">https:\/\/peps.python.org\/pep-0687<\/a><\/p>\n<\/li>\n<li>\n<p>Module State Access from C Extension Methods: <a href=\"https:\/\/peps.python.org\/pep-0573\" rel=\"noopener noreferrer nofollow\">https:\/\/peps.python.org\/pep-0573<\/a><\/p>\n<\/li>\n<li>\n<p>Immortal Objects, Using a Fixed Refcount: <a href=\"https:\/\/peps.python.org\/pep-0683\" rel=\"noopener noreferrer nofollow\">https:\/\/peps.python.org\/pep-0683<\/a><\/p>\n<\/li>\n<li>\n<p>\u0414\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f <code>concurrent.interpreters<\/code>: <a href=\"https:\/\/docs.python.org\/3.14\/library\/concurrent.interpreters.html#module-concurrent.interpreters\" rel=\"noopener noreferrer nofollow\">https:\/\/docs.python.org\/3.14\/library\/concurrent.interpreters.html#module-concurrent.interpreters<\/a><\/p>\n<\/li>\n<li>\n<p>\u0414\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f <code>InterpreterPoolExecutor<\/code>: <a href=\"https:\/\/docs.python.org\/3.14\/library\/concurrent.futures.html#concurrent.futures.InterpreterPoolExecutor\" rel=\"noopener noreferrer nofollow\">https:\/\/docs.python.org\/3.14\/library\/concurrent.futures.html#concurrent.futures.InterpreterPoolExecutor<\/a><\/p>\n<\/li>\n<\/ul>\n<p>\u0410 \u0435\u0449\u0435 \u043c\u043e\u0436\u043d\u043e \u0433\u043b\u044f\u043d\u0443\u0442\u044c \u0441\u0442\u0430\u0442\u044c\u044e \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u0437 \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u043e\u0432 \u043d\u0430\u0448\u0435\u0433\u043e \u0447\u0430\u0442\u0430 \u043d\u0430 \u0434\u0430\u043d\u043d\u0443\u044e \u0442\u0435\u043c\u0443, \u0441 \u0431\u043e\u043b\u044c\u0448\u0438\u043c \u043f\u043e\u0433\u0440\u0443\u0436\u0435\u043d\u0438\u0435\u043c \u0432 \u0434\u0435\u0442\u0430\u043b\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438: <a href=\"https:\/\/habr.com\/ru\/companies\/timeweb\/articles\/922314\/\" rel=\"noopener noreferrer nofollow\">https:\/\/habr.com\/ru\/companies\/timeweb\/articles\/922314<\/a><\/p>\n<p>\u0412\u0441\u0435\u043c \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u0441\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430 \u0438\u043d\u0442\u0435\u0440\u0435\u0441 \u043a \u0434\u0435\u0442\u0430\u043b\u044f\u043c \u043f\u0438\u0442\u043e\u043d\u0430, \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0442\u0430\u043a\u0443\u044e \u0441\u0442\u0430\u0442\u044c\u044e \u0431\u044b\u043b\u043e \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e! \u0412\u044b \u043a\u0440\u0443\u0442\u044b\u0435!<\/p>\n<p>\u0415\u0441\u043b\u0438 \u0432\u0430\u043c \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u0431\u043e\u043b\u044c\u0448\u0435 \u0436\u0435\u0441\u0442\u0438:<\/p>\n<ul>\n<li>\n<p>\u041c\u043e\u0436\u043d\u043e \u043f\u043e\u0434\u043f\u0438\u0441\u0430\u0442\u044c \u043d\u0430 \u043c\u043e\u0439 \u0422\u0413 \u043a\u0430\u043d\u0430\u043b, \u0433\u0434\u0435 \u0442\u0430\u043a\u043e\u0433\u043e \u043e\u0447\u0435\u043d\u044c \u043c\u043d\u043e\u0433\u043e: <a href=\"https:\/\/t.me\/opensource_findings\" rel=\"noopener noreferrer nofollow\">https:\/\/t.me\/opensource_findings<\/a><\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432\u0438\u0434\u0435\u043e \u043f\u0440\u043e \u0433\u043b\u0443\u0431\u043e\u043a\u0438\u0439 \u043f\u0438\u0442\u043e\u043d \u043d\u0430 \u043c\u043e\u0435\u043c \u043a\u0430\u043d\u0430\u043b\u0435: <a href=\"https:\/\/www.youtube.com\/@sobolevn\" rel=\"noopener noreferrer nofollow\">https:\/\/www.youtube.com\/@sobolevn<\/a><\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u0434\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u043c\u043e\u044e \u0440\u0430\u0431\u043e\u0442\u0443 \u043d\u0430\u0434 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u043e\u0439 \u044f\u0434\u0440\u0430 CPython, \u0432\u0438\u0434\u0435\u043e \u0438 \u0441\u0442\u0430\u0442\u044c\u044f\u043c\u0438. \u0415\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u0431\u043e\u043b\u044c\u0448\u0435 \u0445\u043e\u0440\u043e\u0448\u0435\u0433\u043e \u0442\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430: <a href=\"https:\/\/boosty.to\/sobolevn\" rel=\"noopener noreferrer nofollow\">https:\/\/boosty.to\/sobolevn<\/a><\/p>\n<\/li>\n<\/ul>\n<p>\u0414\u043e \u043d\u043e\u0432\u044b\u0445 \u0432\u0441\u0442\u0440\u0435\u0447 \u0432 \u043a\u0438\u0448\u043a\u0430\u0445 \u043f\u0438\u0442\u043e\u043d\u0430!<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \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\/articles\/928054\/\"> https:\/\/habr.com\/ru\/articles\/928054\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<div class=\"tm-iframe_temp\" data-src=\"https:\/\/embedd.srv.habr.com\/iframe\/6874c747aadce8eb96cafb49\" data-style=\"\" id=\"6874c747aadce8eb96cafb49\" width=\"\"><\/div>\n<p>\u041f\u0440\u0438\u0432\u0435\u0442! \u041c\u0435\u043d\u044f \u0437\u043e\u0432\u0443\u0442 \u041d\u0438\u043a\u0438\u0442\u0430 \u0421\u043e\u0431\u043e\u043b\u0435\u0432, \u044f core-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u044f\u0437\u044b\u043a\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f CPython, \u0430 \u0442\u0430\u043a \u0436\u0435 \u0430\u0432\u0442\u043e\u0440 \u0441\u0435\u0440\u0438\u0438 \u0432\u0438\u0434\u0435\u043e \u043f\u0440\u043e \u0435\u0433\u043e \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e.<\/p>\n<p>\u042f \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u044e \u0441\u0432\u043e\u0439 \u0446\u0438\u043a\u043b \u0441\u0442\u0430\u0442\u0435\u0439 \u043d\u0430 \u0445\u0430\u0431\u0440\u0435 \u043f\u0440\u043e \u0434\u0435\u0442\u0430\u043b\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u0438\u0442\u043e\u043d\u0430. \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043f\u0440\u043e \u0441\u0443\u0431\u0438\u043d\u0442\u0435\u0440\u043f\u0435\u0440\u0442\u0430\u0442\u043e\u0440\u044b, \u0438\u0445 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e, \u043f\u0440\u043e\u0448\u043b\u043e\u0435 \u0438, \u043d\u0430\u0434\u0435\u044e\u0441\u044c, \u0441\u0432\u0435\u0442\u043b\u043e\u0435 \u0431\u0443\u0434\u0443\u0449\u0435\u0435. <\/p>\n<p>\u041f\u043e\u0434 \u043a\u0430\u0442\u043e\u043c \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e: \u043d\u043e\u0432\u044b\u0435 \u043f\u0438\u0442\u043e\u043d\u043e\u0432\u0441\u043a\u0438\u0435 API \u0434\u043b\u044f \u0443\u0441\u043a\u043e\u0440\u0435\u043d\u0438\u044f \u0438 \u043f\u0430\u0440\u0430\u043b\u0435\u043b\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0432\u0430\u0448\u0438\u0445 \u043f\u0440\u043e\u0433\u0440\u0430\u043c, \u043f\u0440\u043e \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u044c\u044e, \u043f\u0440\u043e \u0434\u0443\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445. \u041d\u0443 \u0438 \u043c\u043d\u043e\u0433\u043e C \u043a\u043e\u0434\u0430!<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0432 \u0432\u043e\u043f\u0440\u043e\u0441\u0435 \u0438 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u0432\u0430\u043c, \u044f \u0441\u0434\u0435\u043b\u0430\u043b \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0430\u0436\u043d\u044b\u0445 \u0448\u0430\u0433\u043e\u0432: \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u043b \u043f\u043e\u0447\u0442\u0438 \u0432\u0435\u0441\u044c \u043a\u043e\u0434 \u0434\u0430\u043d\u043d\u043e\u0439 \u0444\u0438\u0447\u0438, \u043d\u0430\u0447\u0430\u043b \u043a\u043e\u043c\u043c\u0438\u0442\u044c \u0432 \u0441\u0443\u0431\u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440\u044b \u0438 \u0432\u0437\u044f\u043b \u0438\u043d\u0442\u0435\u0440\u0432\u044c\u044e \u0443 \u0430\u0432\u0442\u043e\u0440\u0430 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430. \u0418\u043d\u0442\u0435\u0440\u0432\u044c\u044e \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e \u0441 \u0440\u0443\u0441\u0441\u043a\u0438\u043c\u0438 \u0438 \u0430\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u0438\u043c\u0438 \u0441\u0443\u0431\u0442\u0438\u0442\u0440\u0430\u043c\u0438. \u0410 \u0435\u0449\u0435 \u044f \u0434\u043e\u0431\u0430\u0432\u0438\u043b \u043a\u0443\u0447\u0443 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u043f\u0440\u044f\u043c\u043e \u0432 \u0432\u0438\u0434\u0435\u043e. \u0421\u0442\u0430\u0432\u044c\u0442\u0435 \u043d\u0430 \u043f\u0430\u0443\u0437\u0443 \u0438 \u0447\u0438\u0442\u0430\u0439\u0442\u0435 \u043a\u043e\u0434.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u0432\u0430\u043c \u0442\u0430\u043a\u043e\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u0438\u043b\u0438 \u0446\u0435\u043b\u0438\u043a\u043e\u043c \u043d\u0435\u0437\u043d\u0430\u043a\u043e\u043c\u043e \u2013 \u0434\u043e\u0431\u0440\u043e \u043f\u043e\u0436\u0430\u043b\u043e\u0432\u0430\u0442\u044c!<\/p>\n<hr\/>\n<h2>\u0427\u0442\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u0432 3.14?<\/h2>\n<p>\u0412 Python \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u0434\u0432\u0435 \u0432\u0430\u0436\u043d\u044b\u0435 \u043d\u043e\u0432\u044b\u0435 \u0447\u0430\u0441\u0442\u0438. \u041f\u0435\u0440\u0432\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u2013 <code>concurrent.interpreters<\/code><\/p>\n<pre><code class=\"python\">&gt;&gt;&gt; from concurrent import interpreters  &gt;&gt;&gt; interp = interpreters.create() &gt;&gt;&gt; interpreters.list_all() [Interpreter(0), Interpreter(1)]  &gt;&gt;&gt; def worker(arg: int) -&gt; None: ...     print('do some work', arg) ...      &gt;&gt;&gt; interp.call(worker, 1)  # \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043a\u043e\u0434 \u0432 \u0441\u0430\u0431\u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440\u0435 do some work 1<\/code><\/pre>\n<p>\u041e\u043d\u0430 \u044f\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 <a href=\"https:\/\/github.com\/python\/cpython\/blob\/main\/Lib\/concurrent\/interpreters\/__init__.py\" rel=\"noopener noreferrer nofollow\">Python \u0410\u041f\u0418<\/a> \u0434\u043b\u044f \u0443\u0434\u043e\u0431\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0441\u0443\u0431\u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440\u0430\u043c\u0438. \u0415\u0433\u043e \u043f\u043e\u043a\u0430 \u043d\u0435 \u0442\u0430\u043a \u043c\u043d\u043e\u0433\u043e, \u043d\u043e \u0443\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0435 \u0432\u0435\u0449\u0438. \u0421\u043a\u043e\u0440\u0435\u0435 \u0432\u0441\u0435\u0433\u043e \u2013 \u0432\u0430\u043c \u043e\u043d\u043e \u043d\u0435 \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u0440\u044f\u043c\u043e \u0432 \u0442\u0430\u043a\u043e\u043c \u0432\u0438\u0434\u0435. \u0414\u0430\u043d\u043d\u043e\u0435 \u0410\u041f\u0418 \u0441\u043a\u043e\u0440\u0435\u0435 \u0434\u043b\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a. \u0410\u043d\u0430\u043b\u043e\u0433\u0438\u044f: \u043a\u0430\u043a \u0447\u0430\u0441\u0442\u043e \u0432\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 \u043c\u043e\u0434\u0443\u043b\u044c <code>threading<\/code> \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e?<\/p>\n<p>\u0412\u0442\u043e\u0440\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u2013 <code>concurrent.futures.InterpreterPoolExecutor<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f <a href=\"https:\/\/github.com\/python\/cpython\/blob\/e89923d36650fe10ce1c6b5f7152638589684004\/Lib\/concurrent\/futures\/interpreter.py#L101\" rel=\"noopener noreferrer nofollow\">\u0430\u043d\u0430\u043b\u043e\u0433\u043e\u043c<\/a> <code>concurrent.futures.ThreadPoolExecutor<\/code>. \u041c\u043e\u0436\u043d\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u043a\u0430\u043a\u0443\u044e-\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0443 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u043f\u0430\u0440\u0430\u043b\u0435\u043b\u043b\u044c\u043d\u043e:<\/p>\n<pre><code class=\"python\">&gt;&gt;&gt; from concurrent.futures import InterpreterPoolExecutor  &gt;&gt;&gt; CPUS = 4 ... with InterpreterPoolExecutor(CPUS) as executor: ...     list(executor.map(worker, [1, 2, 3, 4, 5, 6])) ...      do some work 1 do some work 2 do some work 4 do some work 3 do some work 5 do some work 6 [None, None, None, None, None, None]<\/code><\/pre>\n<p>\u0422\u0443\u0442 \u0443\u0436\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0435\u0435. \u0414\u0430\u043d\u043d\u044b\u0439 \u0410\u041f\u0418 \u043c\u043e\u0436\u043d\u043e \u0438 \u043d\u0443\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c, \u0435\u0441\u043b\u0438 \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u0440\u0430\u0441\u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438\u0442\u044c \u0447\u0442\u043e-\u0442\u043e \u043d\u0430 \u043c\u043d\u043e\u0433\u043e \u0441\u0443\u0431\u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440\u043e\u0432.<\/p>\n<p>\u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u2013 \u043a\u0430\u043a \u043e\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442?<\/p>\n<h3>\u0421\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u0441\u0443\u0431\u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440\u043e\u0432 \u0441 threading \/ multiprocessing \/ free-threading \/ asyncio<\/h3>\n<p>\u041c\u043d\u043e\u0433\u043e\u0437\u0430\u0434\u0430\u0447\u043d\u043e\u0441\u0442\u044c (\u0442\u043e\u0447\u043d\u0435\u0435 \u0435\u0451 \u043e\u0442\u0441\u0443\u0442\u0441\u0432\u0438\u0435) \u2013 \u0434\u043e\u043b\u0433\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u0431\u044b\u043b\u0430 \u0441\u043b\u0430\u0431\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u043e\u0439 CPython. \u0411\u044b\u043b\u043e \u043f\u0440\u0435\u0434\u043f\u0440\u0438\u043d\u044f\u0442\u043e \u043c\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u043d\u044b\u0445 \u043f\u043e\u043f\u044b\u0442\u043e\u043a \u043e\u0431\u043e\u0439\u0442\u0438 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f GIL \u0438 \u0440\u0435\u0448\u0438\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u0434\u043b\u044f \u0440\u0430\u0437\u043d\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u0435\u0432.<\/p>\n<p>\u041f\u0435\u0440\u0432\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u2013 <code>threading<\/code> (\u0432 \u0440\u0435\u0436\u0438\u043c\u0435 \u0441 GIL \u043f\u043e-\u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e), \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u0435\u0441\u043b\u0438 \u0432\u044b \u0432\u044b\u0437\u044b\u0432\u0430\u043b\u0438 \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u0431\u0438\u043d\u0430\u0440\u043d\u044b\u0439 \u043a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0447\u0435\u0440\u0435\u0437 C-API \u043e\u0442\u043f\u0443\u0441\u043a\u0430\u043b GIL. \u041a\u0430\u043a <a href=\"https:\/\/t.me\/opensource_findings\/887\" rel=\"noopener noreferrer nofollow\">\u043c\u043e\u0436\u043d\u043e \u043e\u0442\u043f\u0443\u0441\u0442\u0438\u0442\u044c GIL<\/a>? <\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <a href=\"https:\/\/github.com\/python\/cpython\/blob\/5bbf30e89e7e1cb0a2b9bed9e0e99be291becbd3\/Modules\/mmapmodule.c#L1688-L1690\" rel=\"noopener noreferrer nofollow\">\u043c\u043e\u0434\u0443\u043b\u044c mmap \u0434\u0435\u043b\u0430\u0435\u0442 \u0442\u0430\u043a<\/a>:<\/p>\n<pre><code class=\"cpp\">Py_BEGIN_ALLOW_THREADS m_obj-&gt;data = mmap(NULL, map_size, prot, flags, fd, offset); Py_END_ALLOW_THREADS<\/code><\/pre>\n<p>\u0422\u0430\u043a \u043a\u0430\u043a \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0435 C-API \u0434\u043b\u044f \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f <code>PyThreadState<\/code>, \u043b\u044e\u0431\u043e\u0439 \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c <a href=\"https:\/\/docs.python.org\/3\/c-api\/init.html#c.Py_BEGIN_ALLOW_THREADS\" rel=\"noopener noreferrer nofollow\">\u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438<\/a> \u0438 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u0431\u044b\u0441\u0442\u0440\u0435\u0435. \u041d\u043e \u0442\u0430\u043a \u0434\u0435\u043b\u0430\u044e\u0442 \u043d\u0435 \u0432\u0441\u0435. \u0410 \u0435\u0449\u0435 \u0442\u0430\u043a \u043d\u0435\u043b\u044c\u0437\u044f \u0434\u0435\u043b\u0430\u0442\u044c \u0432 Python \u043a\u043e\u0434\u0435. \u041e\u0442\u0442\u043e\u0433\u043e <code>threading<\/code> \u0432 CPython \u0438\u043c\u0435\u043b \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043d\u0443\u044e \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0441\u0442\u044c. \u0411\u043e\u043b\u0435\u0435 \u0442\u043e\u0433\u043e: \u0442\u0440\u0435\u0434\u044b \u0442\u0440\u0435\u0431\u0443\u044e\u0442 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u043e\u0432 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u043b\u044f \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0434\u0430\u043d\u043d\u044b\u043c.<\/p>\n<p>\u041f\u043e\u0442\u043e\u043c\u0443 \u043f\u043e\u044f\u0432\u0438\u043b\u0441\u044f \u0432\u0442\u043e\u0440\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u2013 <code>multiprocessing<\/code>. \u041a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u0436\u0435 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u043b \u043d\u043e\u0432\u044b\u0435 \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u044b\u0435 Python \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u044b \u0441\u043e \u0441\u0432\u043e\u0435\u0439 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u044c\u044e. \u0414\u0430, \u043c\u043e\u0436\u043d\u043e <a href=\"https:\/\/docs.python.org\/3\/library\/multiprocessing.shared_memory.html#multiprocessing.shared_memory.SharedMemory\" rel=\"noopener noreferrer nofollow\">\u043a\u043e\u0435-\u0447\u0442\u043e \u0448\u0430\u0440\u0438\u0442\u044c<\/a>. \u041d\u043e \u0432\u0441\u0435 \u0440\u0430\u0432\u043d\u043e \u0437\u0430\u0442\u0440\u0430\u0442\u044b \u043d\u0430 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043d\u043e\u0432\u043e\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u0438 <code>*N<\/code> \u043f\u043e\u0442\u0440\u0435\u0431\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u2013 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 \u0432\u0430\u0448 \u0434\u0430\u0442\u0430\u0441\u0435\u0442 \u0438 \u0442\u0430\u043a \u0432\u0435\u0441\u0438\u0442 2\u0413\u0411, \u0435\u0433\u043e \u043e\u0447\u0435\u043d\u044c \u0441\u043b\u043e\u0436\u043d\u043e \u0432\u0437\u044f\u0442\u044c \u0438 \u043f\u0440\u043e\u0434\u0443\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432 \u0441\u043e\u0441\u0435\u0434\u043d\u0438\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043d\u0430 \u0435\u0449\u0435 +2\u0413\u0411. <\/p>\n<p>\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u2013 asyncio. \u041a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043b \u043e\u0442 \u043d\u0430\u0441 \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c \u0432\u0435\u0441\u044c \u043f\u0438\u0442\u043e\u043d, \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 <a href=\"https:\/\/journal.stuffwithstuff.com\/2015\/02\/01\/what-color-is-your-function\/\" rel=\"noopener noreferrer nofollow\">\u0446\u0432\u0435\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0439<\/a>, \u043d\u043e \u043d\u0435 \u0440\u0435\u0448\u0438\u043b \u0444\u0443\u043d\u0434\u0430\u043c\u0435\u043d\u0442\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u043e\u0431\u043b\u0435\u043c. \u041e\u043d \u0432\u0441\u0435 \u0435\u0449\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u043b \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u043e\u0434\u043d\u043e\u0433\u043e GIL, \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u043e\u0434\u043d\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430, \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u043e\u0434\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430. \u041d\u0438\u043a\u0430\u043a \u043d\u0435 \u043f\u043e\u043c\u043e\u0433\u0430\u043b \u0441 CPU-bound \u0437\u0430\u0434\u0430\u0447\u0430\u043c\u0438. \u0424\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u043c \u0433\u0432\u043e\u0437\u0434\u0435\u043c \u0432 \u043a\u0440\u044b\u0448\u043a\u0443 \u0433\u0440\u043e\u0431\u0430 <code>asyncio<\/code> \u0441\u0442\u0430\u043b\u043e \u0442\u043e, \u0447\u0442\u043e \u043d\u0435 \u0431\u044b\u043b\u043e \u043f\u0440\u043e\u0434\u0443\u043c\u0430\u043d\u043e, \u043a\u0430\u043a \u043e\u043d\u043e \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c. \u041e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u043f\u043e\u043d\u044f\u0442\u043d\u044b\u0445 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u043e\u0432, \u044f\u0432\u043d\u044b\u0445 cancelation-scopes, \u0438\u043d\u0442\u0440\u043e\u0441\u043f\u0435\u043a\u0446\u0438\u0438 (<a href=\"https:\/\/t.me\/opensource_findings\/882\" rel=\"noopener noreferrer nofollow\">\u0434\u043e\u0431\u0430\u0432\u044f\u0442 \u0432 3.14<\/a>). \u0418 \u0435\u0449\u0435 \u043d\u0435\u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c, \u043c\u043d\u043e\u0433\u043e \u043f\u043b\u043e\u0445\u0438\u0445 \u0410\u041f\u0418, \u0434\u043e\u0441\u044f\u0433\u0430\u0435\u043c\u044b\u0435 \u043f\u0440\u0435\u0434\u0435\u043b\u044b \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u0441\u043b\u043e\u0436\u043d\u0430\u044f \u043c\u0435\u043d\u0442\u0430\u043b\u044c\u043d\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c, \u043f\u043b\u043e\u0445\u0430\u044f \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044f \u0441 \u043f\u043e\u0442\u043e\u043a\u0430\u043c\u0438, \u0438 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0441 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u0430\u043c\u0438 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438.<\/p>\n<p>\u041f\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u0435 free-threading \u043d\u0435 \u0441\u0442\u0430\u043b\u043e \u043d\u0435\u043e\u0436\u0438\u0434\u0430\u043d\u043d\u043e\u0441\u0442\u044c\u044e. \u041f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0442\u0440\u0435\u0434\u044b \u0434\u0435\u0448\u0435\u0432\u044b \u0432 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438, \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u044e\u0442 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 (\u0447\u0442\u043e, \u0441 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442\u044c \u043a \u043c\u0443\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u043e\u043c\u0443 \u0434\u043e\u0441\u0442\u0443\u043f\u0443, \u0433\u043e\u043d\u043a\u0430\u043c, \u0434\u0435\u0434\u043b\u043e\u043a\u0430\u043c \u0438 \u043f\u0440\u043e\u0447\u0435\u043c\u0443 \u0432\u0435\u0441\u0435\u043b\u044c\u044e \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438). \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u043a\u043b\u044e\u0447\u0430\u0442\u044c GIL \u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c <em>\u043d\u0430\u043a\u043b\u0430\u0434\u043d\u044b\u0435 \u0440\u0430\u0441\u0445\u043e\u0434\u044b \u043d\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442<\/em> \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 free-threading. \u0410 \u0442\u0430\u043a \u0436\u0435 \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u043e\u0431\u043c\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0441\u0432\u043e\u0439 \u043a\u043e\u0434 <code>threading.Lock<\/code> \u0438 \u043f\u0440\u043e\u0447\u0438\u043c\u0438 \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u0430\u043c\u0438. \u041d\u043e \u0432\u0441\u0435 \u0440\u0430\u0432\u043d\u043e \u0431\u0443\u0434\u0443\u0442 \u043c\u0435\u0441\u0442\u0430, \u0434\u0430\u0436\u0435 \u043f\u0440\u044f\u043c\u043e \u0432 <code>builtins<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435\u043b\u044c\u0437\u044f \u0444\u0438\u0437\u0438\u0447\u0435\u0441\u043a\u0438 \u0441\u043f\u0440\u044f\u0442\u0430\u0442\u044c \u043f\u043e\u0434 \u043e\u0434\u043d\u0443 \u043a\u0440\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0441\u0435\u043a\u0446\u0438\u044e (\u043c\u044c\u044e\u0442\u0435\u043a\u0441). \u0427\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0433\u043e\u043d\u043a\u0438 \u0431\u0443\u0434\u0443\u0442 \u0434\u0430\u0436\u0435 \u0432 \u0431\u0438\u043b\u0442\u0438\u043d\u0430\u0445. <a href=\"https:\/\/github.com\/python\/cpython\/issues\/120496\" rel=\"noopener noreferrer nofollow\">\u041f\u0440\u0438\u043c\u0435\u0440<\/a>: \u043e\u0431\u044b\u0447\u043d\u044b\u0435 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440\u044b \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 <code>--disable-gil<\/code>:<\/p>\n<pre><code class=\"python\">import concurrent.futures  N = 10000 for _ in range(100):     it = iter(range(N))     with concurrent.futures.ThreadPoolExecutor() as executor:         data = set(executor.map(lambda _: next(it), range(N)))         assert len(data) == N, f\"Expected {N} distinct elements, got {len(data)}\"  # Traceback (most recent call last): # File \"&lt;python-input-0&gt;\", line 8, in &lt;module&gt; #   assert len(data) == N, f\"Expected {N} distinct elements, got {len(data)}\" #          ^^^^^^^^^^^^^^ # AssertionError: Expected 10000 distinct elements, got 9999<\/code><\/pre>\n<p> \u0421\u0442\u0440\u0435\u043b\u044f\u0435\u043c \u0441\u0435\u0431\u0435 \u0432 \u043d\u043e\u0433\u0438 \u0441 N \u0440\u0443\u043a!<\/p>\n<p>\u0422\u0430\u043a \u0447\u0442\u043e \u2013 \u0441\u0443\u0431\u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440\u044b \u0432\u044b\u0433\u043b\u044f\u0434\u044f\u0442 \u043e\u0447\u0435\u043d\u044c \u0445\u043e\u0440\u043e\u0448\u0438\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u0435\u043c. \u041e\u043d\u0438 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0434\u0435\u0448\u0435\u0432\u044b \u0432 \u0437\u0430\u043f\u0443\u0441\u043a\u0435 (\u043d\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0435\u0449\u0435 \u0431\u044b\u0441\u0442\u0440\u0435\u0435 \u0438 \u043b\u0443\u0447\u0448\u0435 \u0432 \u0431\u0443\u0434\u0443\u0449\u0435\u043c, \u043e \u0447\u0435\u043c \u0435\u0441\u0442\u044c \u0432 \u0432\u0438\u0434\u0435\u043e), \u043a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u043d\u0438\u0445 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441\u043e \u0441\u0432\u043e\u0438\u043c GIL, \u0432\u043d\u0443\u0442\u0440\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u043d\u0435\u0442 \u043b\u043e\u043a\u043e\u0432 \u0438 \u043c\u0443\u0442\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445, \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0434\u043b\u044f CPU \u0438 IO bound \u0437\u0430\u0434\u0430\u0447, \u0435\u0441\u0442\u044c \u0448\u0430\u0440\u0438\u043d\u0433 \u0434\u0430\u043d\u043d\u044b\u0445 \u0431\u0435\u0437 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f (\u043a\u0430\u043a \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0435\u0440\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0438\u043c\u043c\u0443\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u044b\u0445 \u0438 <a href=\"https:\/\/peps.python.org\/pep-0683\" rel=\"noopener noreferrer nofollow\">immortal<\/a> \u0442\u0438\u043f\u043e\u0432, \u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a int, \u0442\u0430\u043a \u0438 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u0430\u044f \u043c\u0430\u0433\u0438\u044f \u0432\u043e\u043a\u0440\u0443\u0433 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f <code>memoryview<\/code>), \u0438 \u0431\u0443\u0434\u0435\u0442 \u0435\u0449\u0435 \u0431\u043e\u043b\u044c\u0448\u0435 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u0432 \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0438\u0445 \u0440\u0435\u043b\u0438\u0437\u0430\u0445.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u043c\u0430\u0433\u0438\u0438 \u0441 <code>memoryview<\/code> \u0438 \u043b\u044e\u0431\u044b\u043c\u0438 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u0431\u0430\u0444\u0435\u0440\u0430\u043c\u0438:<\/p>\n<pre><code class=\"python\">&gt;&gt;&gt; from concurrent import interpreters &gt;&gt;&gt; interp = interpreters.create() &gt;&gt;&gt; queue = interpreters.create_queue()  &gt;&gt;&gt; b = bytearray(b'123') &gt;&gt;&gt; m = memoryview(b) &gt;&gt;&gt; queue.put_nowait(m) &gt;&gt;&gt; interp.exec('(m := queue.get_nowait()); print(m); m[:] = b\"456\"')  # changing memory directly &lt;memory at 0x103274940&gt;  &gt;&gt;&gt; b  # was changed in another interpreter! bytearray(b'456')<\/code><\/pre>\n<p>\u0422\u0430\u043c \u043e\u0434\u0438\u043d \u0438 \u0442\u043e\u0442 \u0436\u0435 \u043e\u0431\u044a\u0435\u043a\u0442! \u041a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0435 \u0431\u044b\u043b\u043e. \u0427\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u043d\u0430\u043c \u0448\u0430\u0440\u0438\u0442\u044c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <code>np.array<\/code> \u0438\u043b\u0438 \u043b\u044e\u0431\u044b\u0435 \u0434\u0440\u0443\u0433\u0438\u0435 <a href=\"https:\/\/docs.python.org\/3\/c-api\/buffer.html\" rel=\"noopener noreferrer nofollow\">\u0431\u0430\u0444\u0435\u0440\u044b<\/a>. \u0412\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043e\u0447\u0435\u043d\u044c \u043f\u0435\u0440\u0441\u043f\u0435\u043a\u0442\u0438\u0432\u043d\u043e. \u041d\u0443 \u0438, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u0441\u0432\u0435\u0440\u0445\u0443 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u043a\u0440\u0443\u0442\u0438\u0442\u044c \u0438 \u043c\u043e\u0434\u0435\u043b\u044c \u0430\u043a\u0442\u043e\u0440\u043e\u0432 (\u043e \u0447\u0435\u043c \u0442\u043e\u0436\u0435 \u0433\u043e\u0432\u043e\u0440\u0438\u043c \u0432 \u0432\u0438\u0434\u0435\u043e), \u0438 <a href=\"https:\/\/github.com\/python\/cpython\/blob\/main\/Modules\/_interpchannelsmodule.c\" rel=\"noopener noreferrer nofollow\">CSP \u043a\u0430\u043a \u0432 Go<\/a>.<\/p>\n<h2>\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u0441\u0443\u0431\u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440\u044b?<\/h2>\n<p>\u0427\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c, \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u0441\u0443\u0431\u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440\u044b, \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043d\u044f\u0442\u044c \u2013 \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440 \u0432 CPython \ud83d\ude42<\/p>\n<p>\u041a\u043e\u0433\u0434\u0430 \u043c\u044b \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043d\u043e\u0432\u044b\u0439 <code>python<\/code> \u043f\u0440\u043e\u0446\u0435\u0441\u0441, \u043c\u044b \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043a\u043e\u0434 \u0438\u0437 \u0444\u0430\u0439\u043b\u0430 <a href=\"https:\/\/github.com\/python\/cpython\/blob\/main\/Python\/pylifecycle.c\" rel=\"noopener noreferrer nofollow\">pylifecycle.c<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043a\u0430\u043a \u0440\u0430\u0437 \u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440, \u0430 \u0442\u0430\u043a \u0436\u0435 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0432\u0441\u0435 \u0434\u0440\u0443\u0433\u0438\u0435 \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u0436\u0438\u0437\u043d\u0435\u043d\u043d\u043e\u0433\u043e \u0446\u0438\u043a\u043b\u0430. \u0422\u0430\u043c \u0435\u0441\u0442\u044c \u0432\u043e\u0442 \u0442\u0430\u043a\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f:<\/p>\n<pre><code class=\"cpp\">static PyStatus pycore_create_interpreter(_PyRuntimeState *runtime,                           const PyConfig *src_config,                           PyThreadState **tstate_p) {     PyStatus status;     PyInterpreterState *interp;     status = _PyInterpreterState_New(NULL, &amp;interp);     if (_PyStatus_EXCEPTION(status)) {         return status;     }     assert(interp != NULL);     assert(_Py_IsMainInterpreter(interp));     _PyInterpreterState_SetWhence(interp, _PyInterpreterState_WHENCE_RUNTIME);     interp-&gt;_ready = 1;      status = _PyConfig_Copy(&amp;interp-&gt;config, src_config);     if (_PyStatus_EXCEPTION(status)) {         return status;     }      \/* Auto-thread-state API *\/     status = _PyGILState_Init(interp);     if (_PyStatus_EXCEPTION(status)) {         return status;     }      \/\/ ...   }<\/code><\/pre>\n<p>\u041e\u043d\u0430 \u0441\u043e\u0437\u0434\u0430\u0441\u0442 \u0432\u0430\u043c \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u2013 \u0433\u043b\u0430\u0432\u043d\u044b\u0439 \u2013 \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440, \u0435\u0433\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435, GIL \u0438 \u0432\u0441\u0435 \u0434\u0440\u0443\u0433\u0438\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0434\u043b\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0432\u0435\u0449\u0438. \u0422\u0435\u043f\u0435\u0440\u044c \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u0435\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0442\u0435 \u0441\u0430\u043c\u044b\u0435 &#171;\u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f&#187;, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u043d\u0430 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \/ \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442. \u0418\u0445 \u0434\u0432\u0430 \u0433\u043b\u0430\u0432\u043d\u044b\u0445: <code>PyThreadState<\/code> (<a href=\"https:\/\/github.com\/python\/cpython\/blob\/f320c951c3220aa6727b581216463e8b3f8bcd6b\/Include\/cpython\/pystate.h#L66\" rel=\"noopener noreferrer nofollow\">\u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043f\u043e\u0442\u043e\u043a\u0430<\/a>) \u0438 <code>PyInterpreterState<\/code> (<a href=\"https:\/\/github.com\/python\/cpython\/blob\/main\/Include\/internal\/pycore_interp_structs.h#L767\" rel=\"noopener noreferrer nofollow\">\u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440\u0430<\/a>), \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043f\u0440\u0438\u0432\u044f\u0437\u0430\u043d\u043e \u043a \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044e \u043f\u043e\u0442\u043e\u043a\u0430. \u041d\u0443 \u0447\u0442\u043e \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u044e. \u0412\u043e\u0442 \u0434\u0435\u0444\u0438\u043d\u0438\u0446\u0438\u0438: <\/p>\n<pre><code class=\"cpp\">typedef struct _ts PyThreadState; typedef struct _is PyInterpreterState;  struct _ts {     \/* See Python\/ceval.c for comments explaining most fields *\/      PyThreadState *prev;     PyThreadState *next;     PyInterpreterState *interp;      \/* The global instrumentation version in high bits, plus flags indicating        when to break out of the interpreter loop in lower bits. See details in        pycore_ceval.h. *\/     uintptr_t eval_breaker;      \/* Currently holds the GIL. Must be its own field to avoid data races *\/     int holds_gil;      \/\/ ... };<\/code><\/pre>\n<p>\u0412\u043d\u0443\u0442\u0440\u0438 \u043c\u043e\u0436\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u043c\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0433\u043e \u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u043e\u0433\u043e. \u0412 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 <code>PyInterpreterState<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u0436\u0435 \u0432 \u0441\u0435\u0431\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0435\u0442 \u0431\u043e\u043b\u044c\u0448\u0435 \u043f\u0440\u0438\u043a\u043b\u0430\u0434\u043d\u044b\u0445 \u0432\u0435\u0449\u0435\u0439. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440: \u0441\u0432\u043e\u0438 <code>builtins<\/code> \u0438 <code>sys<\/code>, \u0441\u0432\u043e\u0438 \u0438\u043c\u043f\u043e\u0440\u0442\u044b, \u0441\u0432\u043e\u0439 GIL \u0432  <code>_gil<\/code> (\u0438\u043b\u0438 \u043e\u0431\u0449\u0438\u0439 \u0432 <code>ceval<\/code> \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 <code>PyInterpreterConfig_SHARED_GIL<\/code>, \u0441\u043c <a href=\"https:\/\/github.com\/python\/cpython\/blob\/180b3eb697bf5bb0088f3f35ef2d3675f9fff04f\/Python\/ceval_gil.c#L499\" rel=\"noopener noreferrer nofollow\">_PyEval_InitGIL<\/a>) \u0438 \u0432\u0441\u0435 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0435 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b:<\/p>\n<pre><code class=\"cpp\">struct _is {     struct _ceval_state ceval;        struct _gc_runtime_state gc;      \/\/ Dictionary of the sys module     PyObject *sysdict;      \/\/ Dictionary of the builtins module     PyObject *builtins;      struct _import_state imports;      \/* The per-interpreter GIL, which might not be used. *\/     struct _gil_runtime_state _gil;      \/* cross-interpreter data and utils *\/     _PyXI_state_t xi;      \/\/ ... };<\/code><\/pre>\n<p>\u0420\u0430\u0437\u043e\u0431\u0440\u0430\u043b\u0438\u0441\u044c: \u0432\u043e\u0442 \u0447\u0442\u043e \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u0442\u0430\u043a\u043e\u0435 &#171;\u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440&#187;. \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043f\u043e\u043d\u0438\u043c\u0430\u0435\u043c, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u0442\u0430\u043a\u0438\u0445 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0439 \u0431\u0443\u0434\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e, \u0442\u043e \u043c\u044b \u0441\u043c\u043e\u0436\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u0445 (\u043f\u043e\u0447\u0435\u043c\u0443 \u043e\u043d\u0438 \u0431\u0443\u0434\u0443\u0442 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u043c\u0438 &#8212; \u043c\u044b \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u0447\u0443\u0442\u044c \u043f\u043e\u0437\u0436\u0435) \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440\u043e\u0432. C-API \u0434\u043b\u044f \u0442\u0430\u043a\u043e\u0433\u043e \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e \u0443\u0436\u0435 \u0441 Python 3.10. \u0421\u043c\u043e\u0442\u0440\u0438\u043c: <a href=\"https:\/\/docs.python.org\/dev\/c-api\/init.html#sub-interpreter-support\" rel=\"noopener noreferrer nofollow\">https:\/\/docs.python.org\/dev\/c-api\/init.html#sub-interpreter-support<\/a><\/p>\n<pre><code class=\"cpp\">PyInterpreterConfig config = {     .use_main_obmalloc = 0,     .allow_fork = 0,     .allow_exec = 0,     .allow_threads = 1,     .allow_daemon_threads = 0,     .check_multi_interp_extensions = 1,     .gil = PyInterpreterConfig_OWN_GIL, };<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\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-467501","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/467501","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=467501"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/467501\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=467501"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=467501"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=467501"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}