Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

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

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

tstack opened this issue May 2, 2012 · 0 comments
Labels
bug Something isn't working fix-in-progress

Comments

@tstack
Copy link

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
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fix-in-progress
Projects
None yet
Development

No branches or pull requests

1 participant