Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
laodouya opened this issue Jul 4, 2023 · 6 comments
Closed

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

laodouya opened this issue Jul 4, 2023 · 6 comments
Labels
bug Something isn't working

Comments

@laodouya
Copy link
Contributor

laodouya commented Jul 4, 2023

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

@lmangani lmangani added the bug Something isn't working label Jul 4, 2023
@laodouya
Copy link
Contributor Author

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
Copy link
Contributor Author

laodouya commented Jul 11, 2023

Or use

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

to replace stderr fd temporarily

@auxten
Copy link
Member

auxten commented Jul 12, 2023

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
Copy link
Contributor

lmangani commented Aug 6, 2023

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

@auxten
Copy link
Member

auxten commented Aug 7, 2023

Still to be fixed

@auxten
Copy link
Member

auxten commented Mar 14, 2024

Fixed #105

@auxten auxten closed this as completed Mar 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants