Open TimChild opened 2 years ago
Using this hash function instead seems to fix the issue for me, but I have no idea what other problems I'll run into with this yet...
import hashlib
def deterministic_hash(*args) -> int:
string = ''.join([str(arg) for arg in args])
return int(hashlib.sha1(string.encode('ascii')).hexdigest(), 16)
Ah, thank you! Sorry, I didn't realize I was opening a duplicate issue. I'm a bit new to opening issues etc.
I actually ended up here from using your pyEX package 👍
Describe the bug The cache persistence only seems to work correctly when there is a single argument in the function call. The cached result is not retrieved for multiple arguments or any keyword arguments in subsequent runtimes (although it does work in the same runtime).
To Reproduce Make a scatch.py:
Run
scratch.py
twice.Expected behavior The first time
scratch.py
is run the expected behavior is seen:The second time, I would expect to see:
Instead, the second (and future runs) result in:
Desktop (please complete the following information):
Additional context I believe the issue is that for multiple arguments or keyword arguments (where a
kwd_mark
object is added as an additional argument) the key is generated from_HashedSeq(key)
instead of justkey[0]
. The hash of_HashedSeq
useshash(tup)
, but the python built-inhash
is only deterministic in the same runtime, not between runtimes.I think the fix probably requires the use of something like
hashlib.sha256()
, but then that only takes bytes, and I'm not sure what the implications of that may be. Maybe some combination withjson.dumps()
?