chdb-io / chdb

chDB is an in-process OLAP SQL Engine 🚀 powered by ClickHouse
https://clickhouse.com/docs/en/chdb
Apache License 2.0
2.03k stars 72 forks source link

Can not redirct stderr in chdb.query() #54

Closed laodouya closed 6 months ago

laodouya commented 1 year ago

Describe the unexpected behaviour In version above 0.10, chdb.query() will print error message in stderr. But it can not redirct or catch into variable.

How to reproduce

import chdb
from io import StringIO
import sys
from contextlib import redirect_stderr

f = StringIO()
with redirect_stderr(f):
    res = chdb.query("select 1", "csv")
    # sys.stderr.write("write stderr in python")
err = f.getvalue()

print("Capture err by redirect_stderr: ", err)

Expected behavior Error msg catched and stored into err variable

laodouya commented 1 year ago

Use https://github.com/minrk/wurlitzer can catch it.

from wurlitzer import pipes

with pipes() as (out, err):
    res = chdb.query("select 1", "csv")

errmsg = err.read()
laodouya commented 1 year ago

Or use

pipe_out, pipe_in = os.pipe()
os.dup2(pipe_in, 2)

to replace stderr fd temporarily

auxten commented 1 year ago

It seems the wurlitzer created a new process to do that. I will fix it in chdb C++ after my "rebasing to 23.6" is finished.

lmangani commented 1 year ago

Can we close this issue or is it still applicable to 0.11.4?

auxten commented 1 year ago

Still to be fixed

auxten commented 6 months ago

Fixed #105