diff options
| author | Guillaume Horel <guillaume.horel@gmail.com> | 2019-04-30 16:35:46 -0400 |
|---|---|---|
| committer | Guillaume Horel <guillaume.horel@gmail.com> | 2019-04-30 16:35:46 -0400 |
| commit | 4c896c3c9cf1bcd1d3236eb58cd0c9a725f25184 (patch) | |
| tree | acd845462801bdae32b64961b3dadac71f6ba12f | |
| parent | 880b79bdf289fa5d3de767e9bd3a97a52e16acf7 (diff) | |
| download | pyisda-4c896c3c9cf1bcd1d3236eb58cd0c9a725f25184.tar.gz | |
raise an exception to prevent zombie processes
| -rw-r--r-- | pyisda/optim.pyx | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/pyisda/optim.pyx b/pyisda/optim.pyx index 0004996..38867be 100644 --- a/pyisda/optim.pyx +++ b/pyisda/optim.pyx @@ -1,7 +1,7 @@ from libc.stdlib cimport abort from libc.stdlib cimport free, malloc from libc.stdio cimport fprintf, stderr -from libc.math cimport exp, sqrt +from libc.math cimport exp, sqrt, NAN from .cdsone cimport JpmcdsStringToStubMethod, TStubMethod from .curve cimport (TCurve, YieldCurve, JpmcdsFreeTCurve, JpmcdsNewTCurve, CONTINUOUS) @@ -107,7 +107,7 @@ def init_context(YieldCurve yc not None, trade_date, value_date, start_date, @cython.cdivision(True) -cdef api double pv(double Z, void* ctx) nogil: +cdef api double pv(double Z, void* ctx) nogil except NAN: cdef: my_ctx* params_ext = <my_ctx*>ctx cds_bootstrap_ctx* params = ¶ms_ext.params @@ -130,8 +130,8 @@ cdef api double pv(double Z, void* ctx) nogil: 1e-10, # xacc */ 1e-10, # facc */ &h) != 0: - fprintf(stderr, "Failed to find hazard rate for: %f\n", S) - abort() + with gil: + raise ValueError(f"Failed to find hazard rate for: {S}") params.cdsCurve.fArray[0].fRate = h if JpmcdsFeeLegPV(params.fl, params.cdsCurve.fBaseDate, params.stepinDate, params.cashSettleDate, @@ -182,8 +182,7 @@ def expected_pv(double[:] tilt, double[:] w, double S0, object ctx): 1e-10, # xacc */ 1e-10, # facc */ &h) != 0: - fprintf(stderr, "Failed to find hazard rate for: %f\n", S) - abort() + raise ValueError(f"Failed to find hazard rate for: {S}") params.cdsCurve.fArray[0].fRate = h if JpmcdsFeeLegPV(params.fl, params.cdsCurve.fBaseDate, params.stepinDate, params.cashSettleDate, |
