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, haypo, mortenab
Priority: normal Keywords:

Created on 2008-12-09 10:13 by mortenab, last changed 2009-01-10 20:55 by facundobatista. 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 (haypo) * (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
2009-01-10 20:55:11facundobatistasetstatus: open -> closed
resolution: out of date
messages: + msg79574
nosy: + facundobatista
2008-12-09 10:32:00hayposetnosy: + haypo
messages: + msg77402
2008-12-09 10:13:32mortenabcreate