我试图理解这种行为。这绝对不是我所期望的。我有两个程序,一个读者和一个作家。阅读器打开一个 RDFlib 图形存储,然后每 2 秒执行一次查询
import rdflib
import random
from rdflib import store
import time
default_graph_uri = "urn:uuid:a19f9b78-cc43-4866-b9a1-4b009fe91f52"
s = rdflib.plugin.get('MySQL', store.Store)('rdfstore')
config_string = "host=localhost,password=foo,user=foo,db=foo"
rt = s.open(config_string,create=False)
if rt != store.VALID_STORE:
s.open(config_string,create=True)
while True:
graph = rdflib.ConjunctiveGraph(s, identifier = rdflib.URIRef(default_graph_uri))
rows = graph.query("SELECT ?id ?value { ?id <http://localhost#ha> ?value . }")
for r in rows:
print r[0], r[1]
time.sleep(2)
print " - - - - - - - - "
第二个程序是向三元存储添加内容的编写器
import rdflib
import random
from rdflib import store
default_graph_uri = "urn:uuid:a19f9b78-cc43-4866-b9a1-4b009fe91f52"
s = rdflib.plugin.get('MySQL', store.Store)('rdfstore')
config_string = "host=localhost,password=foo,user=foo,db=foo"
rt = s.open(config_string,create=False)
if rt != store.VALID_STORE:
s.open(config_string,create=True)
graph = rdflib.ConjunctiveGraph(s, identifier = rdflib.URIRef(default_graph_uri))
graph.add( (
rdflib.URIRef("http://localhost/"+str(random.randint(0,100))),
rdflib.URIRef("http://localhost#ha"),
rdflib.Literal(str(random.randint(0,100)))
)
)
graph.commit()
当我使用编写器提交内容时,我希望看到阅读器上的结果数量增加,但这不会发生。阅读器继续返回与开始时相同的结果。但是,如果我停止阅读器并重新启动它,则会出现新的结果。
有人知道我在做什么错吗?