Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/359.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Web应用程序中的Gremlin Python_Python_Gremlin_Janusgraph_Gremlinpython - Fatal编程技术网

Web应用程序中的Gremlin Python

Web应用程序中的Gremlin Python,python,gremlin,janusgraph,gremlinpython,Python,Gremlin,Janusgraph,Gremlinpython,我有一个python flask web应用程序,它正在使用gremlin\u python查询Janus graph DB。一个基本问题是初始化图遍历对象的正确方法 我是否可以使用Remote(DriverRemoteConnection(…)初始化我的遍历g=traversal()。并在请求之间持久化遍历变量g(所有请求都针对同一个图)。我尝试了这一操作,并开始间歇性地获取tornado.iostream.StreamClosedError 第二个选项是为每个请求创建遍历。我对gremlin

我有一个python flask web应用程序,它正在使用
gremlin\u python
查询Janus graph DB。一个基本问题是初始化图遍历对象的正确方法

  • 我是否可以使用Remote(DriverRemoteConnection(…)初始化我的遍历
    g=traversal()。并在请求之间持久化遍历变量
    g
    (所有请求都针对同一个图)。我尝试了这一操作,并开始间歇性地获取
    tornado.iostream.StreamClosedError
  • 第二个选项是为每个请求创建遍历。我对gremlin python体系结构了解不够;为每个请求创建遍历是否有很大的开销

  • 谢谢

    Gremlin Python是一种Gremlin语言变体实现,请参见

    因此,它确实依赖于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
    
    上面的代码可以工作并加载AirRoutes示例。但是它破坏了所有其他测试,因为下面提到的教程中使用的服务器的默认现代图形已经消失了

    您可以打开到服务器的多个websocket连接,但它们都共享相同的“状态”坏消息是不容易通过API影响这种状态,这是当前体系结构的一个深思熟虑的决定。目前有很多配置yaml和Properties文件以及启动和停止服务器

    我的改进建议是基于这种方法带来的挫折感

    特别是我和你一样“我对gremlin python体系结构的理解还不够透彻”.IMHO这不是因为你或我在理解它方面有问题,而是因为它没有得到足够好的解释。特别是缺少示例。这就是我开始学习的原因:-一个旨在减少gremlin python入门痛苦的教程