[vtkusers] Re: [vtk-developers] patch for turning (almost) all VTK errors into Python exceptions, IMPROVED
Charl P. Botha
cpbotha at cpbotha.net
Tue Aug 8 07:56:25 EDT 2006
On 8/5/06, Prabhu Ramachandran <prabhu_r at users.sf.net> wrote:
> >>>>> "Charl" == Charl P Botha <cpbotha at cpbotha.net> writes:
> Charl> Hi there (Python)-gang, I've made a patch for VTK 5.0 which
> Charl> will turn almost all VTK errors into Python exceptions. It
> Charl> works around the exception non-safety of VTK. Have a look
> Charl> here:
> Charl> http://visualisation.tudelft.nl/~cpbotha/thingies/python_exceptions_vtk5.0.diff
> Charl> What do VTK/Python people think? This definitely fills a
> Charl> niche, and it could be conditionally included in VTK. The
> Charl> only drawback is the extra PyErr_Occurred() call after
> Charl> every VTK method call, and of course the extra line or two
> Charl> of Python code to set up the new vtkEventOutputWindow).
> This is nice, thanks. However, does this work for errors generated by
> VTK objects that were not instantiated in Python? Do exceptions
> "leak" in this case? From what I can tell of the patch, the answer is
> yes. If so is this a problem, and how big is it?
I've made a new and improved solution, see here:
This is much simpler than the previous attempt, but works better. I
made a vtkPythonOutputWindow that turns Errors and Warnings into
RuntimeError and RuntimeWarning Python exceptions, and outputs Text
and DebugText using the Python print command. vtkPythonUtil sets this
OutputWindow as the singleton instance.
The wrapping code still has the check for PyErr_Occurred(), as this is
necessary as the final step of turning the error into an exception.
With this new solution, when VTK is being used from Python, ALL VTK
objects, directly created in Python or not, will generate Python
exceptions when they make use of any of the VTK error or warning
macros. In addition, one can revert to the old behaviour with a
This one is definitely commitable to VTK HEAD.
More information about the vtkusers