Skip to content

Commit

Permalink
fix: Release GIL during server.stop() to allow request release callba…
Browse files Browse the repository at this point in the history
…cks to complete (#381)
  • Loading branch information
rmccorm4 authored Jul 17, 2024
1 parent 8153c2e commit d2abb8b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
5 changes: 0 additions & 5 deletions python/test/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,11 +345,6 @@ def test_ready(self):
server = tritonserver.Server(self._server_options).start()
self.assertTrue(server.ready())

@pytest.mark.xfail(
tritonserver.__version__ <= "2.48.0",
reason="Known issue on stop: Exit timeout expired. Exiting immediately",
raises=tritonserver.InternalError,
)
def test_stop(self):
server = tritonserver.Server(self._server_options).start(wait_until_ready=True)

Expand Down
15 changes: 13 additions & 2 deletions python/tritonserver/_c/tritonserver_pybind.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// Copyright 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -1434,7 +1434,18 @@ class PyServer : public PyWrapper<struct TRITONSERVER_Server> {
owned_ = true;
}

void Stop() const { ThrowIfError(TRITONSERVER_ServerStop(triton_object_)); }
void Stop() const
{
// ServerStop is blocking for the duration of the server exit timeout, so
// ensure to release the GIL. This can allow request release callbacks
// to be interleaved while server is waiting for live requests/models
// to complete. Without releasing GIL, this function may acquire the GIL
// first and block the Triton request from being released/freed, thus
// blocking the server's shutdown in a circular manner thinking a model is
// still alive.
py::gil_scoped_release release;
ThrowIfError(TRITONSERVER_ServerStop(triton_object_));
}

void RegisterModelRepository(
const std::string& repository_path,
Expand Down

0 comments on commit d2abb8b

Please sign in to comment.