From 1393d6e1866c28a051253a08cf7c928bcbd1cad3 Mon Sep 17 00:00:00 2001 From: Jacky <18255193+kthui@users.noreply.github.com> Date: Wed, 7 Aug 2024 10:57:10 -0700 Subject: [PATCH] Release GIL during cancellation check (#372) --- src/pb_cancel.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/pb_cancel.cc b/src/pb_cancel.cc index 4c9b926b..0774261d 100644 --- a/src/pb_cancel.cc +++ b/src/pb_cancel.cc @@ -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 @@ -57,6 +57,9 @@ PbCancel::ShmPayload() bool PbCancel::IsCancelled() { + // Release the GIL. Python objects are not accessed during the check. + py::gil_scoped_release gil_release; + std::unique_lock lk(mu_); // The cancelled flag can only move from false to true, not the other way, so // it is checked on each query until cancelled and then implicitly cached.