【问题标题】:Gremlin docker server connection not workingGremlin docker服务器连接不起作用
【发布时间】:2021-07-06 09:05:52
【问题描述】:

我正在使用官方 docker 容器运行 gremlin 服务器:

docker run --rm -it -p 8182:8182 --name gremlin tinkerpop/gremlin-server

然后我尝试从主机运行以下脚本:

from gremlin_python.process.anonymous_traversal import traversal
from gremlin_python.driver.driver_remote_connection import DriverRemoteConnection


if __name__ == "__main__":

    g = traversal().withRemote(DriverRemoteConnection('ws://localhost:8182', 'g'))
    g.V().drop()
    g.V().addV('person')
    l = g.V().hasLabel('person')
    print(l.toList())

连接似乎有效(没有错误),但查询似乎并未实际执行(gremlin 服务器统计显示没有任何调用)。

更奇怪的是,toList() 调用会阻塞执行,并且什么也不返回。如果然后我停止 docker 容器,python 端的连接将断开。

我正在使用 gremlin 服务器的默认设置。 有人可以帮我了解发生了什么吗?

编辑:我还尝试将 gremlin 配置主机更改为 0.0.0.0。

编辑:所以看起来只有toList 等待答案的原因是因为其他查询尚未实际执行,您需要.next()

【问题讨论】:

    标签: docker gremlin tinkerpop gremlin-server gremlinpython


    【解决方案1】:

    原来有两个错误:

    1. 地址必须以/gremlin结尾,所以在我的例子中是'ws://localhost:8182/gremlin'
    2. 尝试此操作时,出现异常,起初看起来像是连接错误:
    RuntimeError: Event loop is closed
    Exception ignored in: <function ClientResponse.__del__ at 0x7fb532031af0>
    Traceback (most recent call last):
    [..]
      File "/usr/lib/python3.8/asyncio/selector_events.py", line 692, in close
      File "/usr/lib/python3.8/asyncio/base_events.py", line 719, in call_soon
      File "/usr/lib/python3.8/asyncio/base_events.py", line 508, in _check_closed
    RuntimeError: Event loop is closed
    

    这实际上不是连接错误,而是连接未正确关闭的警告。如果您进行调查,您会注意到查询实际上已执行。处理这个问题的正确方法是这样写:

    conn = DriverRemoteConnection('ws://localhost:8182/gremlin', 'g')
    g = traversal().withRemote(conn)
    [do your graph operations]
    conn.close()
    

    有了这个,没有例外,生活是美好的。我很惊讶这没有出现在任何文档中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-10-05
      • 1970-01-01
      • 2013-12-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多