hashlib
contains implementations for hash algorithms. Unfortunately two consecuting calls to hashlib.sha256()
do not produce two different instances of SHA256 but the same one: If called twice hashlib.sha256()
will return the same object each time. So apparently we have a singleton here
This is bad in a all situations where any kind of concurrency is required. Additionally this is very bad in situations where you want to provide a hashing object to some algorithm. In my case: Tests fail as the same object is reused instead of creating a new one.
My question: How an I create two instances of SHA256 (or any other hash algorithm)?
Example:
import hashlib
print(hashlib.sha256())
print(hashlib.sha256())
This will output something like:
<sha256 HASH object @ 0x7fb3611b4710>
<sha256 HASH object @ 0x7fb3611b4710>