question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Built-in hash() method is not deterministic, which breaks cachier since #17

See original GitHub issue

Cachier is broken for me since #17 for string arguments (probably for other built-in objects as well). This comes from the fact that the built-in hash() method is not deterministic between runs in python. Therefore calling it on the arguments of the function for caching purpose does not work between multiple runs because it will hash to different values.

The problematic call to hash() is here.

Repro

Run this script twice in a row and it will re-execute the method test() each time without relying on the cache:

import time
from cachier import cachier

@cachier(pickle_reload=False)
def test(text):
    time.sleep(1)
    print(text)
    print(hash(text))
    return 0

start_time = time.time()
text = 'foo'
print(hash(text))
test(text)
print(time.time() - start_time)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:7

github_iconTop GitHub Comments

2reactions
louismartincommented, Feb 8, 2020

Thanks for fixing this so quickly!

2reactions
shaypal5commented, Feb 8, 2020

Should be solved by release v1.3.3. Please check and let me know how it goes; you should definitely reopen this issue if this doesn’t fix the issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why isn't the hash function deterministic? - Stack Overflow
The default hash is the object's memory address and in no way related to those three properties. Implement __hash__ if you want a...
Read more >
Deterministic hashing of Python data objects - death and gravity
An easy solution seems to be the built-in hash() function, which returns the integer hash of an object. However, it has a couple...
Read more >
7. Cryptographic Hashes - Computer Security - CS 161
The hash function, H H , is deterministic, meaning if you compute H(M) H ( M ) twice with the same input M...
Read more >
Why is string.GetHashCode() different each time I run my ...
In this post I discuss string.GetHashCode(), why it's randomised, and hash-attacks. I also provide a deterministic implementation you can ...
Read more >
Build a Hash Table in Python With TDD
Python comes with a built-in hashlib module, which provides a variety of ... It may seem like hash() is a non-deterministic function, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found