Skip to content

Commit 108e472

Browse files
Simplify GIL management for FetchRow (#311)
Implements @paultiq's suggestion in #87 We can save some overhead of GIL release by only releasing when we need to fetch a new chunk.
2 parents a4a4208 + 1964ad5 commit 108e472

1 file changed

Lines changed: 6 additions & 9 deletions

File tree

src/duckdb_py/pyresult.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -117,16 +117,13 @@ unique_ptr<DataChunk> DuckDBPyResult::FetchNextRaw(QueryResult &query_result) {
117117
}
118118

119119
Optional<py::tuple> DuckDBPyResult::Fetchone() {
120-
{
121-
D_ASSERT(py::gil_check());
120+
if (!result) {
121+
throw InvalidInputException("result closed");
122+
}
123+
if (!current_chunk || chunk_offset >= current_chunk->size()) {
122124
py::gil_scoped_release release;
123-
if (!result) {
124-
throw InvalidInputException("result closed");
125-
}
126-
if (!current_chunk || chunk_offset >= current_chunk->size()) {
127-
current_chunk = FetchNext(*result);
128-
chunk_offset = 0;
129-
}
125+
current_chunk = FetchNext(*result);
126+
chunk_offset = 0;
130127
}
131128

132129
if (!current_chunk || current_chunk->size() == 0) {

0 commit comments

Comments
 (0)