[cctbxbb] pyyaml - iotbx.pdb incompatibility

Luc Bourhis luc_j_bourhis at mac.com
Tue Apr 16 02:08:51 PDT 2013


Hi James,

> Is there any hope that this feature could instead raise an exception or warning, based on the value of some environment variable? As it is, you either have to be blind to the potential for such problems or you must accept that your interpreter is subject to sudden crashing.

there is a more fine-grained solution:

from boost.python import ext

try:
    division_by_zero = ext.is_division_by_zero_trapped()
    ext.trap_exceptions(division_by_zero=False)

    <here you make the call to the library that has issues with NaN and Inf>
finally:
    ext.trap_exceptions(division_by_zero=division_by_zero)

Never ever use that without the try ... finally as it is utterly important to restore the default trapping in all circumstances.
This would be best encapsulated as a context manager actually, so that we can write it simply as

with boost.python.trapping(division_by_zero=False):
    <here you make the call to the library that has issues with NaN and Inf>

I leave that as an exercise to whomever is interested!

FYI we have C++ tools that make it easy to safeguard a call to a C/C++ function from an external library that has such issues.



More information about the cctbxbb mailing list