79656403

Date: 2025-06-06 19:47:01
Score: 2
Natty:
Report link

I don't have an answer, just posting to say that I also have this issue. This is in a Jupyter Notebook file in VS Code.

Example:

import duckdb
import pandas as pd

# Example data
data = {
    "ID": [1, 2, 3],  
    "Name": ["Alice", "Bob", "Charlie"],  
    "Score": [85.5, 90.0, 78.0] 
}

# Create the DataFrame
df = pd.DataFrame(data)

# Make DuckDB Connection, write, and try to close conn.
with duckdb.connect("test.duckdb") as conn:
    conn.execute("CREATE TABLE IF NOT EXISTS table_name AS SELECT * FROM df")
if conn: 
    print('still conn')
    conn.close()
conn

This prints "still conn" and also displays the whole connection string when "conn" is called on the last line. So neither the context manager nor the conn.close() appear to close the connection.

Restarting the kernel DOES work, but I think this is annoying enough that it may keep me from using this in its entirety. Or not use DuckDB in notebooks, I guess?

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Ends in question mark (2):
  • Low reputation (1):
Posted by: jackson