From ff689b026089736282f5114785bc6c51a618f44c Mon Sep 17 00:00:00 2001 From: Scorpion Date: Fri, 25 Oct 2024 16:18:59 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20Python=E6=89=A7=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/core/helper/code_executor/code_executor.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/api/core/helper/code_executor/code_executor.py b/api/core/helper/code_executor/code_executor.py index bca0ef99d01dc4..cb804ab9dc1fa4 100644 --- a/api/core/helper/code_executor/code_executor.py +++ b/api/core/helper/code_executor/code_executor.py @@ -117,3 +117,13 @@ def execute_workflow_code_template(cls, language: CodeLanguage, code: str, input raise e return template_transformer.transform_response(response) + +class Capturing(list): + def __enter__(self): + self._stdout = sys.stdout + sys.stdout = self._stringio = StringIO() + return self + def __exit__(self, *args): + self.extend(self._stringio.getvalue().splitlines()) + del self._stringio # free up some memory + sys.stdout = self._stdout