-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9034 from OpenMined/tauquir/prevent-reset-during-…
…hotreload Prevent server data reset due to Uvicorn hot-reload
- Loading branch information
Showing
3 changed files
with
56 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# future | ||
from __future__ import annotations | ||
|
||
# stdlib | ||
import os | ||
from pathlib import Path | ||
import shutil | ||
import tempfile | ||
|
||
# relative | ||
from ..types.uid import UID | ||
|
||
|
||
def get_named_node_uid(name: str) -> UID: | ||
""" | ||
Get a unique identifier for a named node. | ||
""" | ||
return UID.with_seed(name) | ||
|
||
|
||
def get_temp_dir_for_node(node_uid: UID, dir_name: str = "") -> Path: | ||
""" | ||
Get a temporary directory unique to the node. | ||
Provide all dbs, blob dirs, and locks using this directory. | ||
""" | ||
root = os.getenv("SYFT_TEMP_ROOT", "syft") | ||
p = Path(tempfile.gettempdir(), root, str(node_uid), dir_name) | ||
p.mkdir(parents=True, exist_ok=True) | ||
return p | ||
|
||
|
||
def remove_temp_dir_for_node(node_uid: UID) -> None: | ||
""" | ||
Remove the temporary directory for this node. | ||
""" | ||
rootdir = get_temp_dir_for_node(node_uid) | ||
if rootdir.exists(): | ||
shutil.rmtree(rootdir, ignore_errors=True) |