Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/unblob/identifiers.py: 89%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1import os
2from threading import Lock
4__last_id = 0
5__last_id_lock = Lock()
8def new_id():
9 # NOTE, that uuid4 can not be used, as there are multiple processes at run time,
10 # and as subprocesses inherit the random number state, so uuid4 would generate colliding ids
11 # another option that would not work is to use uuid1, but we could generate the id
12 # at the same time
14 global __last_id # noqa: PLW0603
15 with __last_id_lock:
16 __last_id += 1
17 return f"{os.getpid()}:{__last_id}"