[C++-sig] Redirecting PyErr_Print

Pierre Barbier de Reuille pierre.barbier at cirad.fr
Tue May 4 17:17:08 CEST 2004


When you open a pipe for that, you have to be waiting in a reading
state. If you are not, python will be blocked when trying to write.

Depending on what exactly you want to do, you can just define a function
that takes a string as argument and handle the string as you want the
error strings to be handled. Then, export it to python and define a
pseudo-file with its write method bound to this function. After, you'll
have to replace sys.stderr by an instance of your pseudo class. It will
work too ... It's done that way with most Python GUIs.

Pierre Barbier de Reuille

Le mar 04/05/2004 à 16:47, James Gunn a écrit :
> *** Before acting on this e-mail or opening any attachment you are
> advised to read the disclaimer at the end of this e-mail ***
> 
> Hi all,
>  
> I've read a few of the previous posts with regard to redirecting the
> output of PyErr_Print but I've still not managed to do it yet.
> My problem is that I have a GUI-based app that makes calls to an
> embedded Python interpreter and I need to capture the output of
> errors...more specifically, I really really need to capture the output
> of Py_CompileString.
>  
> I've tried to setup a pipe in a similar way to how Pierre Barbier de
> Reuille described in his post 08/04/2004 (Re:[C++-sig]how to get
> python exception information in c++?) but it gives me problems. It
> seems that nothing gets written to the pipe as calls to read it cause
> it to block/wait.
>  
> Does anyone have any clues? 
>  
> Thanks in advance.
>  
> James Gunn
> Software Developer
> --LongSig
>  
> Computer Bureau
> Communisis DM
> Manston Lane
> Crossgates
> Leeds
> LS15 8AH
>  
> Telephone +44 (0)113 225 5306
> Fax       +44 (0)113 225 5921
> Email     James.Gunn at communisis-dm.co.uk
>  
> 
> **********************************************************************
> Please note: This e-mail and its attachments contain only the opinions
> of the sender and do not necessarily reflect the policy(s) of the
> communisis group in general. 
> 
> Employees of the communisis group are required not to make any
> defamatory statements and not to infringe or authorise any
> infringement of copyright or any other legal right by e-mail. Any such
> communication is therefore outside the scope of employment of the
> individual concerned. The communisis group will not accept any
> liability in respect of such a communication.
> 
> Confidentiality: This e-mail and any attachments, together with their
> contents, are confidential unless otherwise explicitly stated in
> writing by the sender of this e-mail and are for the intended
> recipient only. If they have come to you in error you must not take
> any action in respect of them, which includes but is not limited to
> reproducing, sending or storing them, other than to notifying the
> sender immediately of the mistake, and deleting the e-mail, any
> attachments and any reproductions made by replying to it.
> 
> Viruses: This e-mail and any attachments have been scanned for viruses
> but we cannot guarantee that they are virus free. The recipient should
> check this e-mail and any attachments for viruses. The communisis
> group accepts no responsibility for any damage caused by any virus
> transmitted by this e-mail or any of its attachments. In the event of
> any unauthorised copying or forwarding, the recipient will be required
> to indemnify the communisis group against any claim for loss or damage
> caused by any viruses or otherwise.
> **********************************************************************
> 
> ______________________________________________________________________
> This email has been scanned by the MessageLabs Email Security System.
> For more information please visit http://www.messagelabs.com/email
> ______________________________________________________________________
> 
> 
> ______________________________________________________________________
> _______________________________________________
> C++-sig mailing list
> C++-sig at python.org
> http://mail.python.org/mailman/listinfo/c++-sig
-- 
Pierre Barbier de Reuille

INRA - UMR Cirad/Inra/Cnrs/Univ.MontpellierII AMAP
Botanique et Bio-informatique de l'Architecture des Plantes
TA40/PSII, Boulevard de la Lironde
34398 MONTPELLIER CEDEX 5, France

tel   : (33) 4 67 61 65 77    fax   : (33) 4 67 61 56 68 
-- 
Pierre Barbier de Reuille

INRA - UMR Cirad/Inra/Cnrs/Univ.MontpellierII AMAP
Botanique et Bio-informatique de l'Architecture des Plantes
TA40/PSII, Boulevard de la Lironde
34398 MONTPELLIER CEDEX 5, France

tel   : (33) 4 67 61 65 77    fax   : (33) 4 67 61 56 68 





More information about the Cplusplus-sig mailing list