RDFLib/rdflib (original) (raw)
It looks like the _serial_number_generator() in rdflib/term.py (v3.2.1) is not thread safe. Generators can't be resumed when they are already running. So, if two threads are creating blank nodes at the same time, an exception is likely to be thrown.
Here's some code that reproduces the problem for me:
import rdflib import threading
def makeNode(): while True: rdflib.term.BNode()
th = threading.Thread(target=makeNode) th.daemon = True th.start()
makeNode()
I see the following error when executing the above code:
Traceback (most recent call last):
File "blankNodeRace.py", line 13, in <module>
makeNode()
File "blankNodeRace.py", line 7, in makeNode
rdflib.term.BNode()
File ".../rdflib/term.py", line 250, in __new__
node_id = _sn_gen.next()
ValueError: generator already executing