Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

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

Closed
tstack opened this Issue · 0 comments

2 participants

@tstack

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 referenced this issue from a commit
Bertrand Croq fixes issue #209 cde9179
@gjhiggins gjhiggins closed this
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.