| 178 | } |
| 179 | |
| 180 | Status PyFlightServer::ServeWithSignals() { |
| 181 | // Respect the current Python settings, i.e. only interrupt the server if there is |
| 182 | // an active signal handler for SIGINT and SIGTERM. |
| 183 | std::vector<int> signals; |
| 184 | for (const int signum : {SIGINT, SIGTERM}) { |
| 185 | ARROW_ASSIGN_OR_RAISE(auto handler, ::arrow::internal::GetSignalHandler(signum)); |
| 186 | auto cb = handler.callback(); |
| 187 | if (cb != SIG_DFL && cb != SIG_IGN) { |
| 188 | signals.push_back(signum); |
| 189 | } |
| 190 | } |
| 191 | RETURN_NOT_OK(SetShutdownOnSignals(signals)); |
| 192 | |
| 193 | // Serve until we got told to shutdown or a signal interrupted us |
| 194 | RETURN_NOT_OK(Serve()); |
| 195 | int signum = GotSignal(); |
| 196 | if (signum != 0) { |
| 197 | // Issue the signal again with Python's signal handlers restored |
| 198 | PyAcquireGIL lock; |
| 199 | raise(signum); |
| 200 | // XXX Ideally we would loop and serve again if no exception was raised. |
| 201 | // Unfortunately, gRPC will return immediately if Serve() is called again. |
| 202 | ARROW_UNUSED(PyErr_CheckSignals()); |
| 203 | } |
| 204 | |
| 205 | return Status::OK(); |
| 206 | } |
| 207 | |
| 208 | PyFlightResultStream::PyFlightResultStream(PyObject* generator, |
| 209 | PyFlightResultStreamCallback callback) |