-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Cross-Posted] ipyfilechooser + ipython_blocking = large memory leak #36
Comments
@bryceschober I am able to replicate your behavior in Binder. I don't have any immediate hunch on why that is happening, and debugging memory leaks is well outside my bailiwick. Perhaps someone with more kernel or ipywidgets expertise will pick up something obvious? I looked around for "Python memory leak debug strategies" and came across Modifying your cells slightly in the ipython_blocking repo binder, I used -- # cell 1
!pip install ipyfilechooser pympler -q # cell 2
import ipython_blocking
from pympler import tracker
from ipyfilechooser import FileChooser
from pathlib import Path
# Create and display a FileChooser widget
fc = FileChooser(str(Path.home().resolve()), use_dir_icons=True)
tr = tracker.SummaryTracker()
def path_is_selected():
tr.print_diff()
return bool(fc.selected)
display(fc) # cell 3
%block path_is_selected # cell 4
print(fc.selected_path)
print(fc.selected_filename)
print(fc.selected) Between the callback in cell 2 and the
Perhaps @minrk or @jasongrout see something obvious that jumps out at them? |
I'm definitely not a Python memory leak debugging expert either (quite the opposite). I'm wondering though if the same type of memory leak occurs when you use |
@crahan after a little more poking at this, it looks like the memory leak is happening with pretty much any widget. My next step in this debug journey was trying out tracemalloc. I used their recipe for this syntax -- ### cell 1
import linecache
import os
import tracemalloc
def display_top(snapshot, key_type='lineno', limit=10):
snapshot = snapshot.filter_traces((
tracemalloc.Filter(False, "<frozen importlib._bootstrap>"),
tracemalloc.Filter(False, "<unknown>"),
))
top_stats = snapshot.statistics(key_type)
print("Top %s lines" % limit)
for index, stat in enumerate(top_stats[:limit], 1):
frame = stat.traceback[0]
print("#%s: %s:%s: %.1f KiB"
% (index, frame.filename, frame.lineno, stat.size / 1024))
line = linecache.getline(frame.filename, frame.lineno).strip()
if line:
print(' %s' % line)
other = top_stats[limit:]
if other:
size = sum(stat.size for stat in other)
print("%s other: %.1f KiB" % (len(other), size / 1024))
total = sum(stat.size for stat in top_stats)
print("Total allocated size: %.1f KiB" % (total / 1024))
tracemalloc.start()
### cell 2
import ipywidgets as widgets
slider = widgets.IntSlider(min=0, max=10)
slider
### cell 3
import ipython_blocking
ctx = ipython_blocking.CaptureExecution()
with ctx:
i = 0
while True:
if slider.value >= 5:
break
ctx.step()
i += 1
if i == 100000:
snapshot = tracemalloc.take_snapshot()
break
### cell 4
print(slider.value)
### cell 5
display_top(snapshot, limit=20) It took mybinder maybe 20 seconds to hit that 100k
ipykernel's do_one_iteration() does create a tornado generator but I don't know where to go from there. |
Not sure what the best way is to proceed with this. It does appear from your testing that it's happening across different widgets (including default ipywidgets) and isn't specific to just ipyfilechooser. If anything needs to be modified for ipyfilechooser to help resolve this, I'm happy to investigate further, but I doubt there's much I can do. |
I'll go ahead and close this issue as it appears that this issue is not specifically related to just ipyfilechooser. If this is in error, please feel free to comment and I can look at investigating further. |
When I:
The text was updated successfully, but these errors were encountered: