Merge pull request #5649 from EtiennePerot/temp-file-close

fix: close temporary file after creating it
This commit is contained in:
Timothy Jaeryang Baek 2024-09-24 10:49:38 +02:00 committed by GitHub
commit 8e620b0c2c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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)