Hey all,
I'm wrapping a large number of C++ functions that can raise an exception if the underlying socket connection is lost. While I have figured out how to wrap my "get connection" function to re-establish the connection and/or try other available servers in a list, I cannot figure out a solution to create a try..except wrapper to provide to the 80+ C++ functions.
i.e.
#-------------
*client.pxd*
cdef extern from "rpc/RpcService.h":
cdef cppclass RpcServiceClient:
void getProject(ProjectT&, Guid& id) nogil except +
cdef extern from "client.h":
cdef cppclass Client:
RpcServiceClient proxy() nogil
cdef Client* getClient() nogil except +
*module.pyx*
cdef inline Client* conn() except *:
# wrap getClient() here with try..except if the
# connection was never established
cpdef inline get_project(Guid& guid):
cdef:
ProjectT projT # cpp object
Project project # cdef python class
# this would catch fine in my conn() wrapper
# if the connection had never been established
# the first time. But if the existing connection
# suddenly drops, it will be getProject() that
# raises the exception
conn().proxy().getProject(projT, guid)
project = initProject(projT)
return project
#-------------
Any tips on how I can wrap all of these C++ functions in something like a try_call() ?
If this were pure python, I could simply do something like this:
def try_call(fn, *args, **kwargs):
# try fn(*args, **kwargs) and handle
But obviously I cannot pass these as python objects.
-- justin