Gremlin Python 是 Gremlin 语言变体实现,请参阅http://tinkerpop.apache.org/docs/current/tutorials/gremlin-language-variants/ http://tinkerpop.apache.org/docs/current/tutorials/gremlin-language-variants/.
因此,它确实依赖 GremlinServer 来执行遍历。
分配:
g = traversal().withRemote(DriverRemoteConnection('ws://localhost:8182/gremlin','g'))
将打开到服务器的 websocket 连接。不存在通过保留该连接的副本来“持久”这样的事情。持久化机制全部发生在服务器端。当我尝试以下代码时,我发现了这一点:
from gremlin_python.process.anonymous_traversal import traversal
from gremlin_python.driver.driver_remote_connection import DriverRemoteConnection
import os
g = traversal().withRemote(DriverRemoteConnection('ws://localhost:8182/gremlin','g'))
# test loading a graph
def test_loadGraph():
# make the local file accessible to the server
airRoutesPath=os.path.abspath("air-routes-small.xml")
# drop the existing content of the graph
g.V().drop().iterate()
# read the content from the air routes example
g.io(airRoutesPath).read().iterate()
vCount=g.V().count().next()
assert vCount==1000
上面的代码可以运行并加载航线示例。但它破坏了所有其他测试,因为现在下面提到的教程中使用的服务器的默认现代图已经消失了!
您可以打开与服务器的多个 websocket 连接,但它们都共享底层图的相同“状态”。坏消息是,通过 API 影响这种状态并不容易,这是当前架构的故意决定。目前涉及大量配置 yaml 和属性文件以及启动和停止服务器。
我的改进建议https://issues.apache.org/jira/projects/TINKERPOP/issues/TINKERPOP-2294?filter=allopenissues https://issues.apache.org/jira/projects/TINKERPOP/issues/TINKERPOP-2294?filter=allopenissues是基于这种方法带来的挫败感。
特别是我分享你的“我不太了解 gremlin python 架构”。恕我直言,这并不是因为你或我在理解它方面有问题,而是因为它不是解释了足够好。特别是缺少示例。这就是我开始的原因:http://wiki.bitplan.com/index.php/Gremlin_python http://wiki.bitplan.com/index.php/Gremlin_python- 旨在让 gremlin python 入门变得不那么痛苦的教程。