You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/05/31 15:42:48 UTC

[GitHub] [arrow] lidavidm commented on a diff in pull request #13176: ARROW-16597: [Python][FlightRPC] Force server shutdown at interpreter exit

lidavidm commented on code in PR #13176:
URL: https://github.com/apache/arrow/pull/13176#discussion_r885802461


##########
python/pyarrow/_flight.pyx:
##########
@@ -2516,6 +2517,32 @@ cdef class _ServerMiddlewareWrapper(ServerMiddleware):
             instance.call_completed(exception)
 
 
+cdef class _FlightServerFinalizer(_Weakrefable):
+    """
+    A finalizer that shuts down the server on destruction.
+
+    See ARROW-16597. If the server is still active at interpreter
+    exit, the process may segfault.
+    """
+
+    cdef:
+        shared_ptr[PyFlightServer] server
+
+    def finalize(self):
+        cdef:
+            PyFlightServer* server = self.server.get()
+            CStatus status
+        if server == NULL:
+            return
+        with nogil:
+            status = server.Shutdown()
+        check_flight_status(status)
+        with nogil:
+            status = server.Wait()
+        check_flight_status(status)
+        self.server.reset()

Review Comment:
   It shouldn't be a big deal, but I wrapped it in a try-except.



##########
python/pyarrow/_flight.pyx:
##########
@@ -2516,6 +2517,32 @@ cdef class _ServerMiddlewareWrapper(ServerMiddleware):
             instance.call_completed(exception)
 
 
+cdef class _FlightServerFinalizer(_Weakrefable):
+    """
+    A finalizer that shuts down the server on destruction.
+
+    See ARROW-16597. If the server is still active at interpreter
+    exit, the process may segfault.
+    """
+
+    cdef:
+        shared_ptr[PyFlightServer] server
+
+    def finalize(self):
+        cdef:
+            PyFlightServer* server = self.server.get()
+            CStatus status
+        if server == NULL:
+            return
+        with nogil:
+            status = server.Shutdown()
+        check_flight_status(status)
+        with nogil:
+            status = server.Wait()
+        check_flight_status(status)

Review Comment:
   I simplified it slightly (`operator&` wasn't bound in Python)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org