Created
July 21, 2015 15:16
-
-
Save joernhees/7c90de8ef1ab29aefb66 to your computer and use it in GitHub Desktop.
rdflib hashing test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from multiprocessing import Process, Manager, Lock | |
| import random | |
| def f(d): | |
| from rdflib import URIRef | |
| for i in random.sample(range(1000), 1000): | |
| k = URIRef('foo'+str(i)) | |
| with l: | |
| if k not in d: | |
| d[k] = 0 | |
| d[k] += 1 | |
| if __name__ == '__main__': | |
| manager = Manager() | |
| d = manager.dict() | |
| l = Lock() | |
| p1 = Process(target=f, args=(d,)) | |
| p2 = Process(target=f, args=(d,)) | |
| p1.start() | |
| p2.start() | |
| p1.join() | |
| p2.join() | |
| print d | |
| assert len(d) == 1000 | |
| for v in d.values(): | |
| assert v == 2 |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This was an attempt to provoke a bug with unstable hashing of
URIRefas in RDFLib/rdflib#500 by usingURIRefs as keys of a dict from multiple processes.The idea was that as different processes invoking
hash(URIRef('foo'))return different hashes that if they shared a dict this could lead to items ending in different buckets of thedict. It seems though as ifmanager.dict()doesn't get tricked by this...