From 973efa11085011b22b094541431b5f177026d292 Mon Sep 17 00:00:00 2001 From: Trevor Bergeron Date: Fri, 2 May 2025 00:06:18 +0000 Subject: [PATCH] fix: Guarantee guid thread safety across threads --- bigframes/core/guid.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/bigframes/core/guid.py b/bigframes/core/guid.py index 8930d0760a..55b1be78d9 100644 --- a/bigframes/core/guid.py +++ b/bigframes/core/guid.py @@ -11,11 +11,15 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +import threading +_GUID_LOCK = threading.Lock() _GUID_COUNTER = 0 def generate_guid(prefix="col_"): - global _GUID_COUNTER - _GUID_COUNTER += 1 - return f"bfuid_{prefix}{_GUID_COUNTER}" + global _GUID_LOCK + with _GUID_LOCK: + global _GUID_COUNTER + _GUID_COUNTER += 1 + return f"bfuid_{prefix}{_GUID_COUNTER}"