2

I am running Gremlin Python. Firstly, I did the installation in my local machine following these instructions here then I ran the code of this website here, but I got the following error at this bit:

    heading('SubgraphStrategy - just Texas airports')
    strategy = SubgraphStrategy(vertices=__.has("region","US-TX"), edges=__.hasLabel('route'))
    g2 = g.withStrategies(strategy)
    verts = g2.V().count().next()

RuntimeError: Cannot run the event loop while another loop is running

I verified my connection to a graph database to Gremlin Server, with the following code

%%graph_notebook_config
{
  "host": "localhost",
  "port": 8182,
  "ssl": false,
  "gremlin": {
    "traversal_source": "g"
  }
}

I found some solutions to the "RuntimeError: Cannot run the event loop while another loop is running", like the nest_async, but then I got a different error.

Thank you

1 Answer 1

6

If you are using Gremlin Python, inside a Jupyter notebook then an event loop will already be running. The 3.5.x and 3.6.x Gremlin Python clients have an option you can specify when you create your client object that will enable this to work. All you should need to do is something like this:

from gremlin_python.driver.aiohttp.transport import AiohttpTransport

# other common imports not shown

connection = DriverRemoteConnection(endpoint,'g',
                 transport_factory=lambda:AiohttpTransport(call_from_event_loop=True))

g = traversal().withRemote(connection)

Sign up to request clarification or add additional context in comments.

7 Comments

Hi Kelvin, thank you I did the correction, but I got this error: NameError: name 'AiohttpTransport' is not defined after this query verts = g2.V().count().next()
Which version of the Gremlin Python are you using? The example I shared needs at least the 3.5.0 version.
Hi Kelvin, gremlinpython==3.6.0, the other libraries are: graph-notebook==3.5.3 graphql-core==3.2.1. If you agree I can mark this answer as correct and I will make another post with the entire code as probably I am missing something.
Yes, please. The answer as written should solve the event loop error.
You also need to add an import though for from gremlin_python.driver.aiohttp.transport import AiohttpTransport - I will add that to the answer
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.