Skip to content

Commit 8177040

Browse files
committed
Support with Session() as sess: in chdb session
1 parent bfb4df8 commit 8177040

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

chdb/session/state.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import tempfile
22
import shutil
33

4-
from chdb import query
4+
from chdb import query, g_udf_path
55

66

7-
class Session():
7+
class Session:
88
"""
99
Session will keep the state of query. All DDL and DML state will be kept in a dir.
1010
Dir path could be passed in as an argument. If not, a temporary dir will be created.
1111
1212
If path is not specified, the temporary dir will be deleted when the Session object is deleted.
1313
Otherwise path will be kept.
14-
15-
Note: The default database is "_local" and the default engine is "Memory" which means all data
14+
15+
Note: The default database is "_local" and the default engine is "Memory" which means all data
1616
will be stored in memory. If you want to store data in disk, you should create another database.
1717
"""
1818

@@ -28,8 +28,17 @@ def __del__(self):
2828
if self._cleanup:
2929
self.cleanup()
3030

31+
def __enter__(self):
32+
return self
33+
34+
def __exit__(self, exc_type, exc_value, traceback):
35+
self.cleanup()
36+
3137
def cleanup(self):
32-
shutil.rmtree(self._path)
38+
try:
39+
shutil.rmtree(self._path)
40+
except:
41+
pass
3342

3443
def query(self, sql, fmt="CSV"):
3544
"""

0 commit comments

Comments
 (0)