1

I'm new to this Gremlin-driver called Goblin. I was following the introduction/tutorial on Goblin - Async Python toolkit. As described in the documentation, I created a Python coroutine:

loop = asyncio.get_event_loop()
app = loop.run_until_complete(loop)
app.register(Person, Knows)
async def go(app):
    session = await app.session()
    leif = Person()
    leif.name = 'Leif'
    leif.age = 28
    jon = Person()
    jon.name = 'Jonathan'
    works_with = Knows(leif, jon)
    session.add(leif, jon, works_with)
    await session.flush()
    result = await session.g.E(works_with.id).next()
    assert result is works_with
    people = session.traversal(Person)  # element class based traversal source
    async for person in people:
         print(person)

When I ran the Python script, the program seemed to be running into an infinite loop. Neither result nor errors was shown in console at this point.

Hope anyone can help me! Alan

Alan Wang
  • 11
  • 2

1 Answers1

3

It's hard to say exactly what is going on here, as the sample code is incomplete, and contains errors not related to the Goblin code. For example, the following will throw a type error:

app = loop.run_until_complete(loop)

Make sure you are using Goblin 2.0.0, have a Gremlin Server (TinkerPop 3.2.4) running at localhost:8182, and try the following:

import asyncio
from goblin import element, properties, Goblin

# Model definition
class Person(element.Vertex):
    name = properties.Property(properties.String)
    age = properties.Property(properties.Integer)


class Knows(element.Edge):
    notes = properties.Property(properties.String, default='N/A')


# Set up event loop and app
loop = asyncio.get_event_loop()
app = loop.run_until_complete(Goblin.open(loop))

# Register the models with the app
app.register(Person, Knows)

async def go(app):
    session = await app.session()
    leif = Person()
    leif.name = 'Leif'
    leif.age = 28
    jon = Person()
    jon.name = 'Jonathan'
    works_with = Knows(leif, jon)
    session.add(leif, jon, works_with)
    await session.flush()
    result = await session.g.E(works_with.id).next()
    assert result is works_with
    people = session.traversal(Person)
    async for person in people:
        print(person)
    # Make sure to close the app
    await app.close()

# Run the coroutine
loop.run_until_complete(go(app))

This should run, if not, consider contacting me on Github, as I am the author of this library.

davebshow
  • 66
  • 3