Code Monkey home page Code Monkey logo

Comments (12)

James4Ever0 avatar James4Ever0 commented on May 22, 2024 1

Similar capabilities have been achieved by my modified version of reloading

Use against this code:

from reloading import reloading
import asyncio


@reloading
class mClass:
    someValue = 2

    @reloading
    def someMethod(self):
        @reloading
        def someInnerMethod():
            raise Exception("inner exception")
            return "inside function return"
        raise Exception("exception")
        val = someInnerMethod()
        return val

    @reloading
    async def someOtherMethod(self):
        @reloading
        async def asyncInside():
            raise Exception("inner async exception")
            return "async inside return"
        raise Exception('async exception')
        val = await asyncInside()
        return val

    @reloading
    def runAsync(self):
        loop = asyncio.get_event_loop()
        val = loop.run_until_complete(self.someOtherMethod())
        print("value from async func:", val)
        return val


@reloading
def main():
    MClass = mClass # tricky exception, need to 'step out' one exception to fix this one
    print(MClass)
    val = MClass.someMethod()
    print("return value:", val)
    val = MClass.runAsync()
    print("return async value:", val)
    print("success!")


main()

from reloadium.

James4Ever0 avatar James4Ever0 commented on May 22, 2024 1

debugpy is able to capture 'raised exception' and preserve context.

from reloadium.

dkrystki avatar dkrystki commented on May 22, 2024

@James4Ever0
I think it's a great idea.
Definitely would like that be added but have to see if it's feasible to implement.

from reloadium.

dkrystki avatar dkrystki commented on May 22, 2024

I'm trying to implement this and although feasible I stumbled on a UX/Program logic issue.
For the below example it shouldn't halt the execution since the exception will be handled at the call site (line 11).

2023-01-05_22:28:40

I'm trying to figure out how to detected that the exception will be handled in the future while executing the top most frame.
I've been thinking about using some static analysis and exec function to figure out whether the exception will be handled but this seems a bit hacky and potentially very slow.

Any ideas?

from reloadium.

James4Ever0 avatar James4Ever0 commented on May 22, 2024

I use code parser too to handle such nested try...except problems. You can check how my Hy interpreter patch works. I leave multiple command line switches for turning on/off features. Notice Hy interpreter only turns Hy code into HyTree, where I do my static analysis job. What I do to handle this "checked exception" or "exception within try block" is by scanning the entire AST twice. At first scan, I mark ranges where covered try...except and where not. At second scan, I put another level of try...except around those lines not covered by any try...except. In your case, you should put breakpoints outside those areas, in which those areas may differ from my case. Notice this scan is recursive in Hy, where it shall start from lowest level statements first, then composite ones.

In addition to the scanning technique, I also create some type of exception in my patch, once raised (can be configured to raise automatically?), will not be captured by any "synthetic" try...except code blocks till top-level. This might be applied to your case, but I'm not sure.

from reloadium.

James4Ever0 avatar James4Ever0 commented on May 22, 2024

Talking of speed, I think some filesystem watchdogs plus code stored in Redis will do. Everytime code changes, it shall retrieve latest code from Redis whenever it needs. If no changes were made (changes were reported by watchdogs), no parsing nor code retrieval will be done.

from reloadium.

dkrystki avatar dkrystki commented on May 22, 2024

@James4Ever0
Thanks for your help. I managed to implement this.
Would you like to be a beta tester?

from reloadium.

James4Ever0 avatar James4Ever0 commented on May 22, 2024

Yes I would like to.

from reloadium.

James4Ever0 avatar James4Ever0 commented on May 22, 2024

Also I think generators can be tricky to deal with (functions with "yield" keywords). I would do some experiments since I lack such experience.

from reloadium.

dkrystki avatar dkrystki commented on May 22, 2024

Yes, generators can be tricky. They are not tested that well yet.

Thanks for helping out. Send me an email at [email protected] and I'll add you to our discord channel.

from reloadium.

James4Ever0 avatar James4Ever0 commented on May 22, 2024

Email sent!

from reloadium.

dkrystki avatar dkrystki commented on May 22, 2024

Added in reloadium 0.9.7 and PyCharm plugin 0.9.2

from reloadium.

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.