c++ - try..catch macro wrapper equivalent in cython -


i'm wrapping large number of c++ functions can raise exception if underlying socket connection lost. while have figured out how wrap "get connection" function re-establish connection and/or try other available servers in list, cannot figure out solution create try..except wrapper provide 80+ c++ functions.

#-- client.pxd ---  cdef extern "rpc/rpcservice.h":      cdef cppclass rpcserviceclient:         void getproject(projectt&, guid& id) nogil except +  cdef extern "client.h":     cdef cppclass client:         rpcserviceclient proxy() nogil       cdef client* getclient() nogil except +   #-- module.pxd ---  cdef inline client* conn() except *:    # wrap getclient() here try..except if     # connection never established  cpdef inline get_project(guid& guid):     cdef:          projectt projt  # cpp object         project project # cdef python class      # catch fine in conn() wrapper     # if connection had never been established     # first time. if existing connection     # drops, getproject()     # raises exception     conn().proxy().getproject(projt, guid)      project = initproject(projt)     return project 

any tips on how can wrap of these c++ functions in try_call() ? if pure python, this:

def try_call(fn, *args, **kwargs):     # try fn(*args, **kwargs) , handle  try_call(conn().proxy().getproject, projt, guid) 

but cannot pass these cython functions python objects (or maybe can?).

or in c++:

try_call_or_reconnect conn().proxy().getproject(projt, guid) end_try_call_or_reconnect 

you may want check out decorators

def try_wrapper(x):     try:         x()     except:         dosomethingelse()  @try_wrapper def defyouwanttowrap():     dosomething() 

this may not best tutorial, can point in right direction


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -