aboutsummaryrefslogtreecommitdiffstats
path: root/library/python/runtime_py3/test/subinterpreter/py3_subinterpreters.cpp
diff options
context:
space:
mode:
authorsnermolaev <snermolaev@yandex-team.com>2025-04-15 08:08:40 +0300
committersnermolaev <snermolaev@yandex-team.com>2025-04-15 08:21:15 +0300
commit0ca7cfb39890921e0fc5a77e2972842717989f96 (patch)
tree90f759fbc021bbdbf3430593ff34bf8d082429de /library/python/runtime_py3/test/subinterpreter/py3_subinterpreters.cpp
parent0e221bf1e6683a34b2ce4cd10a015b0669c836be (diff)
downloadydb-0ca7cfb39890921e0fc5a77e2972842717989f96.tar.gz
Revert "Subinterpretor compatible __res module" rXXXXXX
commit_hash:1d9f5675b9d3ddaa44db4472376a06ad3e811e2d
Diffstat (limited to 'library/python/runtime_py3/test/subinterpreter/py3_subinterpreters.cpp')
-rw-r--r--library/python/runtime_py3/test/subinterpreter/py3_subinterpreters.cpp82
1 files changed, 0 insertions, 82 deletions
diff --git a/library/python/runtime_py3/test/subinterpreter/py3_subinterpreters.cpp b/library/python/runtime_py3/test/subinterpreter/py3_subinterpreters.cpp
deleted file mode 100644
index 0a934d4db50..00000000000
--- a/library/python/runtime_py3/test/subinterpreter/py3_subinterpreters.cpp
+++ /dev/null
@@ -1,82 +0,0 @@
-#include "stdout_interceptor.h"
-
-#include <util/stream/str.h>
-
-#include <library/cpp/testing/gtest/gtest.h>
-
-#include <Python.h>
-
-#include <thread>
-#include <algorithm>
-
-struct TSubinterpreters: ::testing::Test {
- static void SetUpTestSuite() {
- Py_InitializeEx(0);
- EXPECT_TRUE(TPyStdoutInterceptor::SetupInterceptionSupport());
- }
- static void TearDownTestSuite() {
- Py_Finalize();
- }
-
- static void ThreadPyRun(PyInterpreterState* interp, IOutputStream& pyout, const char* pycode) {
- PyThreadState* state = PyThreadState_New(interp);
- PyEval_RestoreThread(state);
-
- {
- TPyStdoutInterceptor interceptor{pyout};
- PyRun_SimpleString(pycode);
- }
-
- PyThreadState_Clear(state);
- PyThreadState_DeleteCurrent();
- }
-};
-
-TEST_F(TSubinterpreters, NonSubinterpreterFlowStillWorks) {
- TStringStream pyout;
- TPyStdoutInterceptor interceptor{pyout};
-
- PyRun_SimpleString("print('Hello World')");
- EXPECT_EQ(pyout.Str(), "Hello World\n");
-}
-
-TEST_F(TSubinterpreters, ThreadedSubinterpretersFlowWorks) {
- TStringStream pyout[2];
-
- PyInterpreterConfig cfg = {
- .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* mainState = PyThreadState_Get();
- PyThreadState *sub[2] = {nullptr, nullptr};
- Py_NewInterpreterFromConfig(&sub[0], &cfg);
- ASSERT_NE(sub[0], nullptr);
- Py_NewInterpreterFromConfig(&sub[1], &cfg);
- ASSERT_NE(sub[1], nullptr);
- PyThreadState_Swap(mainState);
-
- PyThreadState* savedState = PyEval_SaveThread();
- std::array<std::thread, 2> threads{
- std::thread{ThreadPyRun, sub[0]->interp, std::ref(pyout[0]), "print('Hello Thread 0')"},
- std::thread{ThreadPyRun, sub[1]->interp, std::ref(pyout[1]), "print('Hello Thread 1')"}
- };
- std::ranges::for_each(threads, &std::thread::join);
- PyEval_RestoreThread(savedState);
-
- PyThreadState_Swap(sub[0]);
- Py_EndInterpreter(sub[0]);
-
- PyThreadState_Swap(sub[1]);
- Py_EndInterpreter(sub[1]);
-
- PyThreadState_Swap(mainState);
-
- EXPECT_EQ(pyout[0].Str(), "Hello Thread 0\n");
- EXPECT_EQ(pyout[1].Str(), "Hello Thread 1\n");
-}