[Python-Dev] test_uuid.py on HP NonStop Python-2.7.5 fails (test case: testIssue8621)
V S, Nagendra (Nonstop Filesystems Team)
nagendra.vs at hp.com
Thu Nov 28 15:25:29 CET 2013
> > Hi,
> > On Thu, Nov 28, 2013 at 7:14 AM, V S, Nagendra (Nonstop Filesystems
> > Team)
> >> on NonStop "uuid.py" falls throw to random.range() call to generate
> >> the random number
> > And indeed, the random module gets identical results in both parent
> > and child after a fork(). This seems to mean that the random module
> > is not safe to use in uuid without taking special care of this fact
> > (e.g. feeding back os.getpid() into the seed).
> Yes, there is an issue with the fallback to random, see my 17 months old bug
> report: http://bugs.python.org/issue15206 The uuid module needs a
> fork() aware random instance like the tempfile module.
Thanks all for your responses. I tried to something similar to what Armin was suggesting. Here is what I have done
random.seed(time()) # or just could be random.seed() <-------------New addition
bytes = [chr(random.randrange(256)) for i in range(16)]
val = uuid.UUID(bytes=bytes, version=4)
With this I was able to get a unique sequences in both parent & child after fork().I have tested this function by calling it a million times & every time there has been a unique sequence both in parent & child. Do you this can be fair enough work around for this problem.
Thanks & Regards
More information about the Python-Dev