Jason
unread,Sep 28, 2011, 3:16:29 PM9/28/11Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to cython-users
Hi everyone,
I am almost finished with a CPython API -> Cython port that I've been
working on, but I am stuck on one last detail. Currently, we have some
callback functionality, and while I am able to get it to work without
exception handling, I can't figure out how to do it handling
exceptions.
Below is one of the tests that is failing:
class GoodException(Exception):
pass
def callback_raise(info, n_reads, other):
raise GoodException
def test_raise_in_consume_fasta_build_readmask():
kh = khmer.new_hashtable(4, 4**4)
try:
kh.consume_fasta_build_readmask(reads_filename, 0, 0,
callback_raise)
assert 0
except GoodException:
pass
except:
raise
What should occur is that the callback function (callback_raise)
should raise GoodException when consume_fasta_build_readmask is
called. However, this does not occur and assert 0 is called.
This is where I think the problem is in my .pyx file:
cdef void _report_fn(const_char_ptr info, void* data,
unsigned int n_reads, unsigned long long other)
except +:
global _callback_obj
_callback_obj(info, n_reads, other)
I'm not sure exactly _how_ I am supposed to handle the exception here.
In the current CPython API code, PyErr_Occurred() is checked, and if
that is the case, then another exception is thrown.
Can anyone point me in the right direction here? I am clearly not C++,
Python, and/or Cython-savvy enough to put all the pieces together. :-)
Thanks,
Jason