reloadware / reloadium

Hot Reloading and Profiling for Python
https://reloadium.io
Apache License 2.0
2.74k stars 56 forks source link

[Feature Request] Frame Transaction #181

Open MeGaNeKoS opened 4 months ago

MeGaNeKoS commented 4 months ago

Frame transaction is to ensure the mutable data got revert back during reloading frame or dropping it. This usefull when you have a function that mutate a list or dictionary and need to reload for some changes.

my_list = [1,2]

def addition(target_list):
    target_list.append(3)
    print("Reload here")

addition(my_list)

In this example, if you reload after appending item to the list, the value stil exist on the outer frame.

One approach that come to my mind is by dumping every time we enter a stack like using pickle. Then if we reload that frame, we can just reload the state of that frame. But this approach have some problem on circular variable.

class A:
   def __init__(self):
        self.b = None
class B:
   def __init__(self):
        self.a = None
a = A()
b = B()
a.b = b
b.a = a