
This issue trackerhas been migrated toGitHub, and is currentlyread-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.
Created on2015-10-29 22:30 byalex, last changed2022-04-11 14:58 byadmin. This issue is nowclosed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| uuid.diff | alex,2015-10-29 22:30 | review | ||
| Messages (5) | |||
|---|---|---|---|
| msg253697 -(view) | Author: Alex Gaynor (alex)*![]() | Date: 2015-10-29 22:30 | |
Right now uuid4 can be implemented one of 3 ways:- If there's a libuuid (and it's not OS X's) it uses that.- Fallback to os.urandom- If that raises an exception, fall back to the random moduleI propose to simplify this to _just_ use os.urandom always. Reasons:- Its security properties are more obviously correct. (There's a large comment in uuid.py about how libuuid doees the wrong thing with fork on OS X, who knows if it's correct on other platforms)- It's simpler.- It's faster:a_gaynor@miranda:~$ python -mtimeit -s "import uuid; import os; import ctypes" "_buffer = ctypes.create_string_buffer(16); uuid._uuid_generate_random(_buffer); bytes(_buffer.raw)"100000 loops, best of 3: 10 usec per loopa_gaynor@miranda:~$ python -mtimeit -s "import uuid; import os; import ctypes" "_buffer = ctypes.create_string_buffer(16); uuid._uuid_generate_random(_buffer); bytes(_buffer.raw)"100000 loops, best of 3: 10.3 usec per loopa_gaynor@miranda:~$ python -mtimeit -s "import uuid; import os; import ctypes" "_buffer = ctypes.create_string_buffer(16); uuid._uuid_generate_random(_buffer); bytes(_buffer.raw)"100000 loops, best of 3: 9.99 usec per loopa_gaynor@miranda:~$ python -mtimeit -s "import uuid; import os; import ctypes" "_buffer = ctypes.create_string_buffer(16); uuid._uuid_generate_random(_buffer); bytes(_buffer.raw)"100000 loops, best of 3: 10.2 usec per loopa_gaynor@miranda:~$ python -mtimeit -s "import uuid; import os; import ctypes" "_buffer = ctypes.create_string_buffer(16); uuid._uuid_generate_random(_buffer); bytes(_buffer.raw)"100000 loops, best of 3: 10.2 usec per loopa_gaynor@miranda:~$a_gaynor@miranda:~$a_gaynor@miranda:~$a_gaynor@miranda:~$a_gaynor@miranda:~$ python -mtimeit -s "import uuid; import os; import ctypes" "os.urandom(16)"100000 loops, best of 3: 8.94 usec per loopa_gaynor@miranda:~$ python -mtimeit -s "import uuid; import os; import ctypes" "os.urandom(16)"100000 loops, best of 3: 8.92 usec per loopa_gaynor@miranda:~$ python -mtimeit -s "import uuid; import os; import ctypes" "os.urandom(16)"100000 loops, best of 3: 8.97 usec per loopa_gaynor@miranda:~$ python -mtimeit -s "import uuid; import os; import ctypes" "os.urandom(16)"100000 loops, best of 3: 8.93 usec per loopa_gaynor@miranda:~$ python -mtimeit -s "import uuid; import os; import ctypes" "os.urandom(16)"100000 loops, best of 3: 8.94 usec per loopa_gaynor@miranda:~$a_gaynor@miranda:~$a_gaynor@miranda:~$ python --versionPython 2.7.3 | |||
| msg253698 -(view) | Author: Alex Gaynor (alex)*![]() | Date: 2015-10-29 22:31 | |
(Note that the speed difference would be even bigger on a recent python, 2.7.3 was before the file descriptor was cached for os.urandom) | |||
| msg253699 -(view) | Author: Barry A. Warsaw (barry)*![]() | Date: 2015-10-29 22:58 | |
On Oct 29, 2015, at 10:30 PM, Alex Gaynor wrote:>Right now uuid4 can be implemented one of 3 ways:If you're hacking on the uuid module, keep in mindissue22807 | |||
| msg253707 -(view) | Author: Donald Stufft (dstufft)*![]() | Date: 2015-10-30 01:57 | |
This looks like a good idea to me, faster and more secure seems like a total win. | |||
| msg253713 -(view) | Author: Roundup Robot (python-dev)![]() | Date: 2015-10-30 03:40 | |
New changeset24bdc4940e81 by Benjamin Peterson in branch '2.7':always use os.urandom for the uuid4 algorithm (closes#25515)https://hg.python.org/cpython/rev/24bdc4940e81New changeset70be1f9c9255 by Benjamin Peterson in branch '3.5':always use os.urandom for the uuid4 algorithm (closes#25515)https://hg.python.org/cpython/rev/70be1f9c9255New changeset756d040aa8e8 by Benjamin Peterson in branch 'default':merge 3.5 (#25515)https://hg.python.org/cpython/rev/756d040aa8e8 | |||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:58:23 | admin | set | github: 69701 |
| 2015-10-30 03:40:45 | python-dev | set | status: open -> closed nosy: +python-dev messages: +msg253713 resolution: fixed stage: resolved |
| 2015-10-30 01:57:45 | dstufft | set | messages: +msg253707 |
| 2015-10-29 22:58:35 | barry | set | nosy: +barry messages: +msg253699 |
| 2015-10-29 22:33:04 | jayvdb | set | nosy: +jayvdb |
| 2015-10-29 22:31:26 | alex | set | messages: +msg253698 |
| 2015-10-29 22:30:56 | alex | create | |