This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: uuid behavior with multiple threads
Type: behavior Stage:
Components: Library (Lib) Versions: Python 2.5
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: facundobatista, mortenab, vstinner
Priority: normal Keywords:

Created on 2008-12-09 10:13 by mortenab, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (3)
msg77401 - (view) Author: Morten Bentsen (mortenab) Date: 2008-12-09 10:13
The uuid module uses a single global buffer for storing random values 
obtained from the system. This can (and does) cause non-uniqueness of 
generated id's when using the uuid4 function in a multithreaded program.

The following snippet shows the problem - _buffer is the global buffer:

    # When the system provides a version-4 UUID generator, use it.
    if _uuid_generate_random:
        return UUID(bytes=_buffer.raw)
msg77402 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2008-12-09 10:31
It looks like the bug is already fixed in Python trunk:

def uuid4():
    """Generate a random UUID."""

    # When the system provides a version-4 UUID generator, use it.
    if _uuid_generate_random:
        _buffer = ctypes.create_string_buffer(16)
        return UUID(bytes=_buffer.raw)

Changeset: r67318. The changeset was not related to this issue, but 
#4363 (Make uuid module functions usable without ctypes).
msg79574 - (view) Author: Facundo Batista (facundobatista) * (Python committer) Date: 2009-01-10 20:55
Yes, _buffer is not longer global.

Thanks for the report!
Date User Action Args
2022-04-11 14:56:42adminsetgithub: 48857
2009-01-10 20:55:11facundobatistasetstatus: open -> closed
resolution: out of date
messages: + msg79574
nosy: + facundobatista
2008-12-09 10:32:00vstinnersetnosy: + vstinner
messages: + msg77402
2008-12-09 10:13:32mortenabcreate