With an environment like that I wouldn't be surprised[1] if something somewhere is only setting sys.stdout, sys.stderr to the console's queues when it is expecting for there to be possible output from some Python code being executed by it, and then restoring it back to the previous values when that code returns. When the wx event loop calls event handlers or other callbacks those are happening at unexpected times (unexpected by the console anyway) and so the sys.stdout and sys.stderr have not been set to where you are expecting them to be at that point in time.
Try saving a reference to sys.stdout and sys.stderr in some Python code that is executed from the console, and then set sys.stdout and sys.stderr to those saved streams at the beginning of your event handlers or callback code.
[1] Because I've written code like that myself in similar situations.
···
On 1/11/12 11:57 AM, Emmanuel Bacry wrote:
Emmanuel Bacry wrote:
The "only" problem I get, is that when I use (within the callbacks) PyErr_.... functions, for instance
PyErr_SetString("There is an error"); \\ Generate an error
PyErr_Print()); \\ prints itI am very surprised because I just don't understand what error stream it uses. It is NOT using the python stream sys.stderr (as my soft in wxPython does)
PyErr_Print imports sys and writes to sys.stderr. What leads you to
believe that's not happening?I am using the qtconsole of ipython with the wx loop. I don't know if you are familiar with that, but it lets you control the ipython kernel (within a wx loop) from a console.
The connection between the console and the kernel is made using TCP using the library zmq.
It works VERY well.So the sys.stderr is set to a TCP client that I can see in the qtconsole
Now, within the C AND within an event callback execution of wxwidgets, I can check that the object sys.stderr is still the same.
Moreover if I do PyRun_SimpleString("print>> sys.stderr 'kjkj'") it works fine, it prints in the qt console
but when I do a PyErr_Print() call it prints the message on the standard stderr (i.e., in the unix terminal)Let me point out that this seems to happen ONLY when these calls are made within a wx call back (not if I make a "direct" call from the qtconsole)
--
Robin Dunn
Software Craftsman