So I've determined the situation with reproducibility of the hash
randomization.

You can set the hash randomization seed using the environment variable
PYTHONHASHSEED, like:

$PYTHONHASHSEED=42 python3.3
Python 3.3.0a3 (v3.3.0a3:0b53b70a40a0, May  1 2012, 11:39:35)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> hash('a')
-5486454195961207828
>>> ^D

$PYTHONHASHSEED=42 python3.3
Python 3.3.0a3 (v3.3.0a3:0b53b70a40a0, May  1 2012, 11:39:35)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> hash('a')
-5486454195961207828

That's the good news.  The bad news is that it's impossible to get
that seed when it is set automatically by the interpreter.  That's
because the seed is used to generate a secret, and that secret is what
the interpreter keeps track of.  You can access the secret with

>>> from ctypes import c_int, pythonapi
>>> c_int.in_dll(pythonapi, "_Py_HashSecret").value
1758302383

but that for example corresponds to the seed of 42 above.

So if we want to print the seed for testing, we have to manually set
it, which means that we would have to spawn a new Python process to
run the tests.  For SymPy bot, this is not a problem, because it does
that anyway.  For just running the tests normally, we would have to
change the test runner to do this.  Do people think that this is worth
the trouble?  If a test failure comes out of the blue that is caused
by some rare hash randomization seed, it would be nice to be able to
reproduce it (similar to failures with the random module seed).  I'm
not sure how much of a burdon this would be on the test runner (maybe
it wouldn't be any at all, I haven't tried it yet).

Also, can anyone comment on how py.test might handle this situation?

By the way, the information above comes from
http://mail.python.org/pipermail/python-porting/2012-May/000317.html.

Aaron Meurer

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sympy?hl=en.

Reply via email to