mirror of
https://github.com/apache/arrow.git
synced 2026-10-28 16:47:19 +08:00
Use 'except *' to handle exceptions in Cython
This commit is contained in:
1 parent
445eb87cd9
commit
10dccb6749
3 files changed
+36
-43
No files matched your search
@@ -35,22 +35,21 @@ namespace flight {
|
||||
/// Python.
|
||||
class ARROW_PYTHON_EXPORT PyFlightServerVtable {
|
||||
public:
|
||||
// Must return int so Cython will propagate exceptions
|
||||
std::function<int(PyObject*, const arrow::flight::Criteria*,
|
||||
std::unique_ptr<arrow::flight::FlightListing>*)>
|
||||
std::function<void(PyObject*, const arrow::flight::Criteria*,
|
||||
std::unique_ptr<arrow::flight::FlightListing>*)>
|
||||
list_flights;
|
||||
std::function<int(PyObject*, const arrow::flight::FlightDescriptor&,
|
||||
std::unique_ptr<arrow::flight::FlightInfo>*)>
|
||||
std::function<void(PyObject*, const arrow::flight::FlightDescriptor&,
|
||||
std::unique_ptr<arrow::flight::FlightInfo>*)>
|
||||
get_flight_info;
|
||||
std::function<int(PyObject*, const arrow::flight::Ticket&,
|
||||
std::unique_ptr<arrow::flight::FlightDataStream>*)>
|
||||
std::function<void(PyObject*, const arrow::flight::Ticket&,
|
||||
std::unique_ptr<arrow::flight::FlightDataStream>*)>
|
||||
do_get;
|
||||
std::function<int(PyObject*, std::unique_ptr<arrow::flight::FlightMessageReader>)>
|
||||
std::function<void(PyObject*, std::unique_ptr<arrow::flight::FlightMessageReader>)>
|
||||
do_put;
|
||||
std::function<int(PyObject*, const arrow::flight::Action&,
|
||||
std::unique_ptr<arrow::flight::ResultStream>*)>
|
||||
std::function<void(PyObject*, const arrow::flight::Action&,
|
||||
std::unique_ptr<arrow::flight::ResultStream>*)>
|
||||
do_action;
|
||||
std::function<int(PyObject*, std::vector<arrow::flight::ActionType>*)> list_actions;
|
||||
std::function<void(PyObject*, std::vector<arrow::flight::ActionType>*)> list_actions;
|
||||
};
|
||||
|
||||
class ARROW_PYTHON_EXPORT PyFlightServer : public arrow::flight::FlightServerBase {
|
||||
@@ -74,7 +73,7 @@ class ARROW_PYTHON_EXPORT PyFlightServer : public arrow::flight::FlightServerBas
|
||||
};
|
||||
|
||||
/// \brief A callback that obtains the next result from a Flight action.
|
||||
typedef std::function<int(PyObject*, std::unique_ptr<arrow::flight::Result>*)>
|
||||
typedef std::function<void(PyObject*, std::unique_ptr<arrow::flight::Result>*)>
|
||||
PyFlightResultStreamCallback;
|
||||
|
||||
/// \brief A ResultStream built around a Python callback.
|
||||
|
||||
+14
-20
@@ -445,8 +445,8 @@ cdef class RecordBatchStream(FlightDataStream):
|
||||
return new CRecordBatchStream(reader)
|
||||
|
||||
|
||||
cdef int _list_flights(void* self, const CCriteria* c_criteria,
|
||||
unique_ptr[CFlightListing]* listing) except -1:
|
||||
cdef void _list_flights(void* self, const CCriteria* c_criteria,
|
||||
unique_ptr[CFlightListing]* listing) except *:
|
||||
"""Callback for implementing ListFlights in Python."""
|
||||
cdef:
|
||||
vector[CFlightInfo] flights
|
||||
@@ -458,11 +458,10 @@ cdef int _list_flights(void* self, const CCriteria* c_criteria,
|
||||
type(info)))
|
||||
flights.push_back(deref((<FlightInfo> info).info.get()))
|
||||
listing.reset(new CSimpleFlightListing(flights))
|
||||
return 0
|
||||
|
||||
|
||||
cdef int _get_flight_info(void* self, CFlightDescriptor c_descriptor,
|
||||
unique_ptr[CFlightInfo]* info) except -1:
|
||||
cdef void _get_flight_info(void* self, CFlightDescriptor c_descriptor,
|
||||
unique_ptr[CFlightInfo]* info) except *:
|
||||
"""Callback for implementing Flight servers in Python."""
|
||||
cdef:
|
||||
FlightDescriptor py_descriptor = \
|
||||
@@ -474,11 +473,10 @@ cdef int _get_flight_info(void* self, CFlightDescriptor c_descriptor,
|
||||
"a FlightInfo instance, but got {}".format(
|
||||
type(result)))
|
||||
info.reset(new CFlightInfo(deref((<FlightInfo> result).info.get())))
|
||||
return 0
|
||||
|
||||
|
||||
cdef int _do_put(void* self,
|
||||
unique_ptr[CFlightMessageReader] reader) except -1:
|
||||
cdef void _do_put(void* self,
|
||||
unique_ptr[CFlightMessageReader] reader) except *:
|
||||
"""Callback for implementing Flight servers in Python."""
|
||||
cdef:
|
||||
FlightRecordBatchReader py_reader = FlightRecordBatchReader()
|
||||
@@ -488,11 +486,10 @@ cdef int _do_put(void* self,
|
||||
descriptor.descriptor = reader.get().descriptor()
|
||||
py_reader.reader.reset(reader.release())
|
||||
(<object> self).do_put(descriptor, py_reader)
|
||||
return 0
|
||||
|
||||
|
||||
cdef int _do_get(void* self, CTicket ticket,
|
||||
unique_ptr[CFlightDataStream]* stream) except -1:
|
||||
cdef void _do_get(void* self, CTicket ticket,
|
||||
unique_ptr[CFlightDataStream]* stream) except *:
|
||||
"""Callback for implementing Flight servers in Python."""
|
||||
py_ticket = Ticket(ticket.ticket)
|
||||
result = (<object> self).do_get(py_ticket)
|
||||
@@ -501,11 +498,10 @@ cdef int _do_get(void* self, CTicket ticket,
|
||||
"a FlightDataStream")
|
||||
stream[0] = unique_ptr[CFlightDataStream](
|
||||
(<FlightDataStream> result).to_stream())
|
||||
return 0
|
||||
|
||||
|
||||
cdef int _do_action_result_next(void* self,
|
||||
unique_ptr[CResult]* result) except -1:
|
||||
cdef void _do_action_result_next(void* self,
|
||||
unique_ptr[CResult]* result) except *:
|
||||
"""Callback for implementing Flight servers in Python."""
|
||||
try:
|
||||
action_result = next(<object> self)
|
||||
@@ -515,21 +511,19 @@ cdef int _do_action_result_next(void* self,
|
||||
result.reset(new CResult(deref((<Result> action_result).result.get())))
|
||||
except StopIteration:
|
||||
result.reset(nullptr)
|
||||
return 0
|
||||
|
||||
|
||||
cdef int _do_action(void* self, const CAction& action,
|
||||
unique_ptr[CResultStream]* result) except -1:
|
||||
cdef void _do_action(void* self, const CAction& action,
|
||||
unique_ptr[CResultStream]* result) except *:
|
||||
"""Callback for implementing Flight servers in Python."""
|
||||
cdef:
|
||||
function[cb_result_next] ptr = &_do_action_result_next
|
||||
py_action = Action(action.type, pyarrow_wrap_buffer(action.body))
|
||||
responses = (<object> self).do_action(py_action)
|
||||
result.reset(new CPyFlightResultStream(responses, ptr))
|
||||
return 0
|
||||
|
||||
|
||||
cdef int _list_actions(void* self, vector[CActionType]* actions) except -1:
|
||||
cdef void _list_actions(void* self, vector[CActionType]* actions) except *:
|
||||
"""Callback for implementing Flight servers in Python."""
|
||||
cdef:
|
||||
CActionType action_type
|
||||
@@ -539,7 +533,7 @@ cdef int _list_actions(void* self, vector[CActionType]* actions) except -1:
|
||||
action_type.type = tobytes(action[0])
|
||||
action_type.description = tobytes(action[1])
|
||||
actions.push_back(action_type)
|
||||
return 0
|
||||
|
||||
|
||||
cdef class FlightServerBase:
|
||||
"""A Flight service definition."""
|
||||
|
||||
@@ -122,17 +122,17 @@ cdef extern from "arrow/flight/api.h" namespace "arrow" nogil:
|
||||
|
||||
# Callbacks for implementing Flight servers
|
||||
# Use typedef to emulate syntax for std::function<void(...)>
|
||||
ctypedef int cb_list_flights(object, const CCriteria*,
|
||||
unique_ptr[CFlightListing]*)
|
||||
ctypedef int cb_get_flight_info(object, const CFlightDescriptor&,
|
||||
unique_ptr[CFlightInfo]*)
|
||||
ctypedef int cb_do_put(object, unique_ptr[CFlightMessageReader])
|
||||
ctypedef int cb_do_get(object, const CTicket&,
|
||||
unique_ptr[CFlightDataStream]*)
|
||||
ctypedef int cb_do_action(object, const CAction&,
|
||||
unique_ptr[CResultStream]*)
|
||||
ctypedef int cb_list_actions(object, vector[CActionType]*)
|
||||
ctypedef int cb_result_next(object, unique_ptr[CResult]*)
|
||||
ctypedef void cb_list_flights(object, const CCriteria*,
|
||||
unique_ptr[CFlightListing]*)
|
||||
ctypedef void cb_get_flight_info(object, const CFlightDescriptor&,
|
||||
unique_ptr[CFlightInfo]*)
|
||||
ctypedef void cb_do_put(object, unique_ptr[CFlightMessageReader])
|
||||
ctypedef void cb_do_get(object, const CTicket&,
|
||||
unique_ptr[CFlightDataStream]*)
|
||||
ctypedef void cb_do_action(object, const CAction&,
|
||||
unique_ptr[CResultStream]*)
|
||||
ctypedef void cb_list_actions(object, vector[CActionType]*)
|
||||
ctypedef void cb_result_next(object, unique_ptr[CResult]*)
|
||||
|
||||
cdef extern from "arrow/python/flight.h" namespace "arrow::py::flight" nogil:
|
||||
cdef cppclass PyFlightServerVtable:
|
||||
|
||||
Reference in new issue
Block a user