Giter Club home page Giter Club logo

Comments (3)

davebshow avatar davebshow commented on September 26, 2024

Hi @patricknee. What is happening here is that when you return the first message in the loop you are short circuiting the iteration so the response is not properly closed. Normally, the response receives None from the driver, closes the response, and calls StopAsyncIteration. However, you never get there because you just return the first result. There are two ways to avoid this:

  1. If you are unsure of the number of results that will be returned in the stream, you can store them in a container until the iteration finishes:
result = []
resp = await conn.submit(gremlin=script, bindings=binding)
async for msg in resp:
    result.append(msg)
return result
  1. If you are sure that you are only going to get one result back on the stream you can do this:
resp = await conn.submit(gremlin=script, bindings=binding)
result = await resp.fetch_data()
resp.close()
return result

However, the first approach is preferable to the second because this assures that you read all the returned results from the underlying stream. When Python 3.6 becomes generally available, you will be able to simply yield results as they come in, and this will be the best option of all:

resp = await conn.submit(gremlin=script, bindings=binding)
async for msg in resp:
    yield msg

I hope that helps and thanks for your interest in Goblin. Let me know if you have any more questions.

from goblin.

patricknee avatar patricknee commented on September 26, 2024

Yes, I was pretty sure it was the iterable nature of response, and I should have tried handling the result in a list... I tried a few other things (appending strings) before writing. Thanks for the quick response.

from goblin.

davebshow avatar davebshow commented on September 26, 2024

No worries. I'm going to go ahead and close this issue.

from goblin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.