Skip to content

Commit 7e0df85

Browse files
committed
Use a single capsule, don't cleanup default connection twice.
1 parent 25d4b77 commit 7e0df85

3 files changed

Lines changed: 5 additions & 10 deletions

File tree

_duckdb-stubs/__init__.pyi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1437,7 +1437,6 @@ __interactive__: bool
14371437
__jupyter__: bool
14381438
__standard_vector_size__: int
14391439
__version__: str
1440-
_clean_default_connection: pytyping.Any # value = <capsule object>
14411440
apilevel: str
14421441
paramstyle: str
14431442
threadsafety: int

duckdb/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@
6666
__interactive__,
6767
__jupyter__,
6868
__standard_vector_size__,
69-
_clean_default_connection,
7069
aggregate,
7170
alias,
7271
apilevel,
@@ -292,7 +291,6 @@
292291
"__jupyter__",
293292
"__standard_vector_size__",
294293
"__version__",
295-
"_clean_default_connection",
296294
"aggregate",
297295
"alias",
298296
"apilevel",

src/duckdb_py/duckdb_python.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ void InitializeModuleState(py::module_ &m) {
3939
SetModuleState(state_ptr);
4040

4141
// https://pybind11.readthedocs.io/en/stable/advanced/misc.html#module-destructors
42-
auto capsule = py::capsule(state_ptr, [](void *p) { delete static_cast<DuckDBPyModuleState *>(p); });
42+
auto capsule = py::capsule(state_ptr, [](void *p) {
43+
auto state = static_cast<DuckDBPyModuleState *>(p);
44+
DuckDBPyModuleState::SetGlobalModuleState(nullptr);
45+
delete state;
46+
});
4347
m.attr("__duckdb_state") = capsule;
4448
}
4549

@@ -1133,12 +1137,6 @@ PYBIND11_MODULE(DUCKDB_PYTHON_LIB_NAME, m,
11331137
.value("keyword", PySQLTokenType::PY_SQL_TOKEN_KEYWORD)
11341138
.value("comment", PySQLTokenType::PY_SQL_TOKEN_COMMENT)
11351139
.export_values();
1136-
1137-
// we need this because otherwise we try to remove registered_dfs on shutdown when python is already dead
1138-
auto clean_default_connection = []() {
1139-
DuckDBPyConnection::Cleanup();
1140-
};
1141-
m.add_object("_clean_default_connection", py::capsule(clean_default_connection));
11421140
}
11431141

11441142
} // namespace duckdb

0 commit comments

Comments
 (0)