"docs/vscode:/vscode.git/clone" did not exist on "b844b99ad309b05f37b1acb5360c82be7b16281d"
Unverified Commit eae3d481 authored by Cyrus Leung's avatar Cyrus Leung Committed by GitHub
Browse files

[Bugfix] Use temporary directory in registry (#9721)

parent e74f2d44
import importlib import importlib
import os
import pickle import pickle
import subprocess import subprocess
import sys import sys
...@@ -423,9 +424,13 @@ _T = TypeVar("_T") ...@@ -423,9 +424,13 @@ _T = TypeVar("_T")
def _run_in_subprocess(fn: Callable[[], _T]) -> _T: def _run_in_subprocess(fn: Callable[[], _T]) -> _T:
with tempfile.NamedTemporaryFile() as output_file: # NOTE: We use a temporary directory instead of a temporary file to avoid
# issues like https://stackoverflow.com/questions/23212435/permission-denied-to-write-to-my-temporary-file
with tempfile.TemporaryDirectory() as tempdir:
output_filepath = os.path.join(tempdir, "registry_output.tmp")
# `cloudpickle` allows pickling lambda functions directly # `cloudpickle` allows pickling lambda functions directly
input_bytes = cloudpickle.dumps((fn, output_file.name)) input_bytes = cloudpickle.dumps((fn, output_filepath))
# cannot use `sys.executable __file__` here because the script # cannot use `sys.executable __file__` here because the script
# contains relative imports # contains relative imports
...@@ -442,7 +447,7 @@ def _run_in_subprocess(fn: Callable[[], _T]) -> _T: ...@@ -442,7 +447,7 @@ def _run_in_subprocess(fn: Callable[[], _T]) -> _T:
raise RuntimeError(f"Error raised in subprocess:\n" raise RuntimeError(f"Error raised in subprocess:\n"
f"{returned.stderr.decode()}") from e f"{returned.stderr.decode()}") from e
with open(output_file.name, "rb") as f: with open(output_filepath, "rb") as f:
return pickle.load(f) return pickle.load(f)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment