Skip to content

Commit

Permalink
Release Python GIL in C++ class constructor (#493)
Browse files Browse the repository at this point in the history
  • Loading branch information
csukuangfj authored Dec 20, 2023
1 parent ef8d112 commit 7634f5f
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
3 changes: 2 additions & 1 deletion sherpa-onnx/python/csrc/offline-recognizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ void PybindOfflineRecognizer(py::module *m) {

using PyClass = OfflineRecognizer;
py::class_<PyClass>(*m, "OfflineRecognizer")
.def(py::init<const OfflineRecognizerConfig &>(), py::arg("config"))
.def(py::init<const OfflineRecognizerConfig &>(), py::arg("config"),
py::call_guard<py::gil_scoped_release>())
.def(
"create_stream",
[](const PyClass &self) { return self.CreateStream(); },
Expand Down
3 changes: 2 additions & 1 deletion sherpa-onnx/python/csrc/offline-tts.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ void PybindOfflineTts(py::module *m) {

using PyClass = OfflineTts;
py::class_<PyClass>(*m, "OfflineTts")
.def(py::init<const OfflineTtsConfig &>(), py::arg("config"))
.def(py::init<const OfflineTtsConfig &>(), py::arg("config"),
py::call_guard<py::gil_scoped_release>())
.def_property_readonly("sample_rate", &PyClass::SampleRate)
.def(
"generate",
Expand Down
3 changes: 2 additions & 1 deletion sherpa-onnx/python/csrc/online-recognizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ void PybindOnlineRecognizer(py::module *m) {

using PyClass = OnlineRecognizer;
py::class_<PyClass>(*m, "OnlineRecognizer")
.def(py::init<const OnlineRecognizerConfig &>(), py::arg("config"))
.def(py::init<const OnlineRecognizerConfig &>(), py::arg("config"),
py::call_guard<py::gil_scoped_release>())
.def(
"create_stream",
[](const PyClass &self) { return self.CreateStream(); },
Expand Down
3 changes: 2 additions & 1 deletion sherpa-onnx/python/csrc/voice-activity-detector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ void PybindVoiceActivityDetector(py::module *m) {
using PyClass = VoiceActivityDetector;
py::class_<PyClass>(*m, "VoiceActivityDetector")
.def(py::init<const VadModelConfig &, float>(), py::arg("config"),
py::arg("buffer_size_in_seconds") = 60)
py::arg("buffer_size_in_seconds") = 60,
py::call_guard<py::gil_scoped_release>())
.def(
"accept_waveform",
[](PyClass &self, const std::vector<float> &samples) {
Expand Down

0 comments on commit 7634f5f

Please sign in to comment.