我正在尝试理解这种行为。这绝对不是我所期望的。我有两个程序,一个是阅读器,一个是编写器。读取器打开一个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()我希望在我使用写入器提交东西时,阅读器上的结果数量会增加,但这并没有发生。读取器继续返回与启动时相同的结果。但是,如果我停止阅读器并重新启动它,就会出现新的结果。
有人知道我做错了什么吗?
发布于 2009-12-08 02:32:16
一个简单的解决方法是将"graph.commit()“放在"graph = rdflib.ConjunctiveGraph(...)”行之后在reader中。我不确定原因是什么,为什么在读之前提交可以解决这个问题。我猜是这样:
https://stackoverflow.com/questions/1860282
复制相似问题