From d4bf844caac314b3ba3957728851e44469eb4313 Mon Sep 17 00:00:00 2001
From: Mateen Ulhaq <mulhaq2005@gmail.com>
Date: Fri, 13 Oct 2023 15:14:42 -0700
Subject: [PATCH] fix: warning if /tmp directory not found for memory_tempfile.
 Fixes #1

---
 src/utils/point_cloud.py | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/src/utils/point_cloud.py b/src/utils/point_cloud.py
index d16cc2e..1a73910 100644
--- a/src/utils/point_cloud.py
+++ b/src/utils/point_cloud.py
@@ -3,7 +3,8 @@
 import os
 import re
 import subprocess
-import tempfile
+import traceback
+import warnings
 from typing import Optional
 
 import numpy as np
@@ -17,6 +18,20 @@
 except ImportError:
     import tempfile
 
+    warnings.warn("Could not import memory_tempfile. Falling back to tempfile.")
+except Exception as e:
+    import tempfile
+
+    warnings.warn(
+        "Could not create MemoryTempfile. Falling back to tempfile. "
+        "Without the /tmp directory, this may lead to slower pc_error metrics. "
+        "If you have a tmpfs at a different location, consider specifying it: "
+        "tempfile = MemoryTempfile(['/path/to/tmpdir']). "
+        "Otherwise, you can ignore this warning, since the default works too. "
+        "Exception message:\n"
+        f"{''.join(traceback.format_exception(None, e, e.__traceback__))}"
+    )
+
 
 def pc_write(pc: np.ndarray, file):
     assert pc.ndim == 2 and pc.shape[1] == 3