Giter Club home page Giter Club logo

Comments (7)

liampauling avatar liampauling commented on July 24, 2024

Ah nice find, you can see that under the try except there is some code which attempts to shutdown the socket. Regarding the pull it might be cleaner if it called self.stop() unless you disagree?

from betfair.

agberk avatar agberk commented on July 24, 2024

I clearly wasn't thinking when I added that finally block - the loop is only ever going to get executed once with that in there.

I agree about calling the stop method instead.

I've changed the raises to just logging.error(...) calls and then added self.stop().

I changed the test_read_loop_error test to call _read_loop() and then assert not self.betfair_stream._running - not sure if this is the best way to test it?

If the raise is removed and changed to a logging.error call, it means that exceptions.SocketError is actually no longer used anywhere in the package; do you want to get rid of it?

When this PR gets merged, I'll update the logging PR to switch the naked logging.error call to obtain a module logger and then use that.

from betfair.

liampauling avatar liampauling commented on July 24, 2024

I need an error to be raised if there is a timeout or another error or my framework will not know that there is an issue and the stream needs to be restarted / reconnect. I agree with the addition of self.stop() but I think an error has to be raised.

from betfair.

agberk avatar agberk commented on July 24, 2024

I think I misunderstood your reason for calling stop() - I thought it was so that it would break out of the loop and call the socket cleanup code.

Clearly if the exception is still raised, it will never reach that cleanup code even after calling stop() and having _running set to False.

However, just calling stop() before raise will set _running to False which will allow me to check the aliveness of the thread, and still throw the exception.

Shall I just create a new branch / PR and put that in there since there's a load of rubbish which isn't applicable now in this one?

from betfair.

liampauling avatar liampauling commented on July 24, 2024

Hmm you are right raising the error means the socket will never be cleaned unless the entire while loop is placed in a try/except and a finally with the stop + cleanup code but that doesn't seem very pythonic.

I think the logical thing to do is to move the clean up code into stop(), because the socket gets recreated during the start() process anyway.

from betfair.

agberk avatar agberk commented on July 24, 2024

Agreed, I think the socket cleanup code should go into stop().

from betfair.

agberk avatar agberk commented on July 24, 2024

I've redone the PR in #52

from betfair.

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.