serve: ending the server removes the image encoder's scratch directory (#914)
This commit is contained in:
1 parent
4f131fcdcc
commit
e02815a5e5
2 files changed
+35
-1
No files matched your search
+7
-1
@@ -1722,6 +1722,12 @@ class Vision:
|
||||
except Exception:
|
||||
self.proc.kill()
|
||||
|
||||
def shutdown(self):
|
||||
"""#914: close() for good: the server ends, so the encoder's directory (one ~10 MB .sve per image, on a tmpfs
|
||||
/tmp that is RAM) goes with it instead of piling up with every start. unload() keeps it for the restart."""
|
||||
self.close()
|
||||
shutil.rmtree(self.dir, ignore_errors=True)
|
||||
|
||||
|
||||
def gpu_list(cfg: dict) -> list[int]:
|
||||
"""The config's "gpu": one card (2), or several for a layer split ([0, 2] or "0,2"), numbered as nvidia-smi
|
||||
@@ -4942,7 +4948,7 @@ def main() -> int:
|
||||
time.sleep(1) # Windows never delivers Ctrl+C to an untimed Event.wait()
|
||||
except KeyboardInterrupt:
|
||||
print("\n[strata] stopping (Ctrl+C again to end the engine at once) ...", flush=True)
|
||||
closers = [httpd.shutdown, getattr(engine, "close", None), vision.close if vision else None,
|
||||
closers = [httpd.shutdown, getattr(engine, "close", None), vision.shutdown if vision else None,
|
||||
hub.close if hub is not None else None]
|
||||
for close in filter(None, closers):
|
||||
try:
|
||||
|
||||
@@ -3783,5 +3783,33 @@ class VisionArgs(unittest.TestCase):
|
||||
["--max-tokens", "1024", "--min-tokens", "768"])
|
||||
|
||||
|
||||
class VisionShutdown(unittest.TestCase):
|
||||
"""#914: ending the server removes the encoder's scratch directory; unloading keeps it."""
|
||||
|
||||
def test_shutdown_removes_the_work_dir_but_close_keeps_it(self):
|
||||
import serve.server as server
|
||||
with tempfile.TemporaryDirectory() as t:
|
||||
d = Path(t) / "strata-vision-x"
|
||||
d.mkdir()
|
||||
(d / "k.sve").write_bytes(b"x")
|
||||
v = server.Vision.__new__(server.Vision)
|
||||
v.dir = d
|
||||
|
||||
class Proc:
|
||||
stdin = io.StringIO()
|
||||
|
||||
def wait(self, timeout=None):
|
||||
return 0
|
||||
|
||||
def kill(self):
|
||||
pass
|
||||
|
||||
v.proc = Proc()
|
||||
v.close()
|
||||
self.assertTrue((d / "k.sve").exists())
|
||||
v.shutdown()
|
||||
self.assertFalse(d.exists())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user