Skip to content

fix: Guarantee guid thread safety across threads #1684

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 5, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions bigframes/core/guid.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,19 @@
# 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
import typing

_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}"


class SequentialUIDGenerator:
Expand Down