Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Hash arguments list more robustly.

Apparently, python's hash() function does not return consistent results across python sessions. It's useful to be able to cache calls in one process and read them in another, so that's a problem. To get consistent hashes, use pickle.dumps to get a string representation of arguments, and hashlib.md5 to hash the result.

Note that pickle could be made faster by specifying a 2nd parameter at the expense of losing compatibility with older versions of python.
  • Loading branch information...
commit fb823bed864d29d6164fbc463ed3423ac87aaa72 1 parent bd4e355
@jwmerrill jwmerrill authored
Showing with 5 additions and 2 deletions.
  1. +5 −2 src/cache/
7 src/cache/
@@ -1,3 +1,6 @@
+import hashlib
+import pickle
# local dependencies
from .version import __version__
@@ -168,9 +171,9 @@ def _prepare_key(key, *args, **kwargs):
items = kwargs.items()
hashable_args = (args, tuple(items))
- args_key = hash(hashable_args)
+ args_key = hashlib.md5(pickle.dumps(hashable_args)).hexdigest()
- return "%s/args:%x" % (key, args_key)
+ return "%s/args:%s" % (key, args_key)
class LocalCache:
Please sign in to comment.
Something went wrong with that request. Please try again.