Skip to content

Blank node _serial_number_generator() is not thread-safe #209

Closed
tstack opened this Issue May 2, 2012 · 0 comments

2 participants

@tstack
tstack commented May 2, 2012

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
@bcroq bcroq added a commit that referenced this issue May 3, 2012
@bcroq bcroq fixes issue #209 cde9179
@gjhiggins gjhiggins closed this Jun 2, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.