Persisting objects while debugging
What's the best way to keep expensive data objects around while debugging lightweight functions that accept said data as a parameter?
Specifically, i have a custom object that invokes and wraps a pandas.DataFrame. This takes about 10 seconds to load each time i refresh the debugger. I'd like to keep the object "around" while i make changes and reload helper functions that interact with the object.
I've tried a few different approaches below but none of which really harness pycharm. I just want to make sure i'm not missing a feature.
- Pickling.
- Jupyter Notebook with separate cell containing a the invocation of the expensive object with factory function that provides a deepcopy. While this works, i'm losing out on the benefits of the pycharm visual debugger
Is there a solution that involves attaching to a local process? I'm less familiar with exactly how/what this actually does. I also played around with a coroutine that returns a call to a function containing a breakpoint but can only get the visual debugger to work on the first iteration.
Please sign in to leave a comment.
I think i found an approach that works for me but would be curious if there's any additional suggestions out there.
running below on visual debugger seems to allow me to modify the code being tested in spam mod without having to to regenerate that data created in the first function call.
def expensive_closure():
...
return infinite_cheap_generator
def test_coroutine():
while True:
try:
bar = yield
importlib.reload(spam)
spam.foo(bar)
except:
pass
if __name___......
factory = expensive_closure()
testing = test_coroutine()
next(testing) # prime coroutine
test_gen = (testing.send(x) for x in factory)
while true:
next(test_gen)