Jump to content
iqrf

TPythonInputOutput separation Python Error

Recommended Posts

Hello,
is there any way to remap PyErr_Print using a custom function? I would like to log the error output on a separate sheet. Now everything ends up in TPythonInputOutput. Or can it be done differently?
Thanks for the idea.

Share this post


Link to post

I think the best you can is to refer to the PythonEngine's DoRedirectIO sources

 

the line

 sys.stdin=sys.stderr=sys.stdout=DebugOutput() 

redirects error output onto PythonEngine.IO

so far you could try to use other redirection somewhere in your code

 

Hope this helps

Share this post


Link to post
from io import StringIO
import sys

old_stderr = sys.stderr
sys.stderr = mystderr = StringIO()

# examine mystderr.getvalue()

 

Share this post


Link to post

Thanks, it works.

 try
    MaskFPUExceptions(True);
    PythonEngine1.ExecStrings(Memo1.Lines);

  except
    errorMessage := MainModule.mystderr.getvalue();
    ErrorLog(errorMessage);
  end;

I would just like to continuously catch errors if someone writes in the Python code for example print("Error example 1", file=sys.stderr)
or
sys.stderr.write("Error Example 2")
The current solution only prints everything at once, with the same timestamp.

Thanks.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×