소스 검색

fix: close temporary file after creating it.

This fixes "The process cannot access the file
because it is being used by another process"
errors on Windows.

The file is still automatically deleted by the
`os.unlink` call later in the function.

Updates #5606
Fixes #5642
Etienne Perot 7 달 전
부모
커밋
fdd27aa321
1개의 변경된 파일2개의 추가작업 그리고 1개의 파일을 삭제
  1. 2 1
      backend/open_webui/apps/webui/utils.py

+ 2 - 1
backend/open_webui/apps/webui/utils.py

@@ -87,7 +87,7 @@ def load_toolkit_module_by_id(toolkit_id, content=None):
     # Create a temporary file and use it to define `__file__` so
     # Create a temporary file and use it to define `__file__` so
     # that it works as expected from the module's perspective.
     # that it works as expected from the module's perspective.
     temp_file = tempfile.NamedTemporaryFile(delete=False)
     temp_file = tempfile.NamedTemporaryFile(delete=False)
-
+    temp_file.close()
     try:
     try:
         with open(temp_file.name, "w", encoding="utf-8") as f:
         with open(temp_file.name, "w", encoding="utf-8") as f:
             f.write(content)
             f.write(content)
@@ -131,6 +131,7 @@ def load_function_module_by_id(function_id, content=None):
     # Create a temporary file and use it to define `__file__` so
     # Create a temporary file and use it to define `__file__` so
     # that it works as expected from the module's perspective.
     # that it works as expected from the module's perspective.
     temp_file = tempfile.NamedTemporaryFile(delete=False)
     temp_file = tempfile.NamedTemporaryFile(delete=False)
+    temp_file.close()
     try:
     try:
         with open(temp_file.name, "w", encoding="utf-8") as f:
         with open(temp_file.name, "w", encoding="utf-8") as f:
             f.write(content)
             f.write(content)