diff options
-rw-r--r-- | Lib/test/test_uuid.py | 28 | ||||
-rw-r--r-- | Lib/uuid.py | 13 | ||||
-rw-r--r-- | Misc/NEWS | 3 |
3 files changed, 44 insertions, 0 deletions
diff --git a/Lib/test/test_uuid.py b/Lib/test/test_uuid.py index c22b6af3e0..43fa656102 100644 --- a/Lib/test/test_uuid.py +++ b/Lib/test/test_uuid.py @@ -457,6 +457,34 @@ class TestUUID(TestCase): equal(u, uuid.UUID(v)) equal(str(u), v) + def testIssue8621(self): + import os + import sys + if os.name != 'posix': + return + + # On at least some versions of OSX uuid.uuid4 generates + # the same sequence of UUIDs in the parent and any + # children started using fork. + fds = os.pipe() + pid = os.fork() + if pid == 0: + os.close(fds[0]) + value = uuid.uuid4() + os.write(fds[1], value.hex.encode('latin1')) + os._exit(0) + + else: + os.close(fds[1]) + parent_value = uuid.uuid4().hex + os.waitpid(pid, 0) + child_value = os.read(fds[0], 100).decode('latin1') + + self.assertNotEqual(parent_value, child_value) + + + + def test_main(): support.run_unittest(TestUUID) diff --git a/Lib/uuid.py b/Lib/uuid.py index b4554e4942..fda9fe1914 100644 --- a/Lib/uuid.py +++ b/Lib/uuid.py @@ -427,6 +427,19 @@ try: if hasattr(lib, 'uuid_generate_time'): _uuid_generate_time = lib.uuid_generate_time + # The uuid_generate_* functions are broken on MacOS X 10.6, as noted + # in issue #8621 the function generates the same sequence of values + # in the parent process and all children created using fork (unless + # those children use exec as well). + # + # Assume that the uuid_generate functions are broken from 10.6 onward, + # the test can be adjusted when a later version is fixed. + import sys + if sys.platform == 'darwin': + import os + if int(os.uname()[2].split('.')[0]) >= 10: + _uuid_generate_random = _uuid_generate_time = None + # On Windows prior to 2000, UuidCreate gives a UUID containing the # hardware address. On Windows 2000 and later, UuidCreate makes a # random UUID and UuidCreateSequential gives a UUID containing the @@ -348,6 +348,9 @@ C-API Library ------- +- Issue #8621: uuid.uuid4() returned the same sequence of values in the + parent and any children created using ``os.fork`` on MacOS X 10.6. + - Issue #8567: Fix precedence of signals in Decimal module: when a Decimal operation raises multiple signals and more than one of those signals is trapped, the specification determines the order in which |