nebula-python客户端的例子在具体运行中无法获得结果

import random
import sys
import time
from nebula3.gclient.net import ConnectionPool
from nebula3.Config import Config
from nebula3.data.ResultSet import ResultSet
from nebula3.mclient import MetaCache, HostAddr
from nebula3.sclient.GraphStorageClient import GraphStorageClient
from nebula3.sclient.ScanResult import ScanResult


def prepare_data():
    config = Config()
    config.max_connection_pool_size = 1
    # init connection pool
    connection_pool = ConnectionPool()
    # the graphd server's address
    assert connection_pool.init([('192.168.1.30', 9669)], config)
    client = connection_pool.get_session('root', 'nebula')
    client.execute(
        'CREATE SPACE IF NOT EXISTS ScanSpace('
        'PARTITION_NUM=10,'
        'vid_type=FIXED_STRING(20));'
        'USE ScanSpace;'
        'CREATE TAG IF NOT EXISTS person(name string, age int);'
        'CREATE EDGE IF NOT EXISTS friend(start int, end int);'
    )
    time.sleep(5)

    for id in range(20):
        vid = 'person' + str(id)
        cmd = 'INSERT VERTEX person(name, age) ' 'VALUES \"{}\":(\"{}\", {})'.format(
            vid, vid, id
        )
        print(client.execute(cmd))
    for id in range(20):
        src_id = 'person' + str(id)
        dst_id = 'person' + str(20 - id)
        start = random.randint(2000, 2010)
        end = random.randint(2010, 2020)
        cmd = 'INSERT EDGE friend(start, end) ' 'VALUES \"{}\"->\"{}\":({}, {})'.format(
            src_id, dst_id, start, end
        )
        print(client.execute(cmd))
    client.release()
    connection_pool.close()


def scan_person_vertex(graph_storage_client):
    resp = graph_storage_client.scan_vertex(
        space_name='ScanSpace', tag_name='person', limit=1
    )
    print('======== Scan vertexes in ScanSpace ======')
    while resp.has_next():
        result = resp.next()
        for vertex_data in result:
            print(vertex_data)


def scan_person_edge(graph_storage_client):
    resp = graph_storage_client.scan_edge(
        space_name='ScanSpace', edge_name='friend', limit=100
    )
    print('======== Scan edges in ScanSpace ======')
    while resp.has_next():
        result = resp.next()
        for edge_data in result:
            print(edge_data)


if __name__ == '__main__':
    meta_cache = None
    graph_storage_client = None
    try:
        # the metad servers's address
        meta_cache = MetaCache([('192.168.1.30', 9559), ], 50000)
        graph_storage_client = GraphStorageClient(meta_cache, storage_addrs=[HostAddr(host='192.168.1.30', port=9779)])
        prepare_data()
        scan_person_vertex(graph_storage_client)
        scan_person_edge(graph_storage_client)

    except Exception as x:
        import traceback

        print(traceback.format_exc())
        if graph_storage_client is not None:
            graph_storage_client.close()
    finally:
        if graph_storage_client is not None:
            graph_storage_client.close()
        if meta_cache is not None:
            meta_cache.close()

在运行至scan_person_vertex时,程序长时间没有输出,且没有相关报错

相关代码与github中的例子几乎没有差异,只是调整了连接配置
https://github.com/vesoft-inc/nebula-python/blob/master/example/ScanVertexEdgeExample.py

你这个地方,是部署了几个 storage ?可以试一下改成:

graph_storage_client = GraphStorageClient(meta_cache)

此话题已在最后回复的 30 天后被自动关闭。不再允许新回复。