Skip to content

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

Closed
@louismartin

Description

@louismartin

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)

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions