Skip to content

Commit cb0267d

Browse files
fix: Guarantee guid thread safety across threads (#1684)
1 parent 761c364 commit cb0267d

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

bigframes/core/guid.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,19 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
14+
import threading
1515
import typing
1616

17+
_GUID_LOCK = threading.Lock()
1718
_GUID_COUNTER = 0
1819

1920

2021
def generate_guid(prefix="col_"):
21-
global _GUID_COUNTER
22-
_GUID_COUNTER += 1
23-
return f"bfuid_{prefix}{_GUID_COUNTER}"
22+
global _GUID_LOCK
23+
with _GUID_LOCK:
24+
global _GUID_COUNTER
25+
_GUID_COUNTER += 1
26+
return f"bfuid_{prefix}{_GUID_COUNTER}"
2427

2528

2629
class SequentialUIDGenerator:

0 commit comments

Comments
 (0)