GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — Use real references to `Graphics`, proper garbage collection in ipython and jupyter by kushalkolar · Pull Request #546 · fastplotlib/fastplotlib Conversation
|
| if IS_IPYTHON: | |
| # remove any references that ipython might have made | |
| ip = get_ipython() | |
| # get all references in ipython namespace | |
| references = list(ip.user_ns.keys()) | |
| for ref in references: | |
| if ip.user_ns[ref] is graphic: | |
| # we found the graphic, remove from ipython | |
| ip.del_var(ref) | |
| break |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
No more weakreferences to Graphics! 🥳
🥳 ❤️
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
| for ref in references: | ||
| if ip.user_ns[ref] is graphic: | ||
| # we found the graphic, remove from ipython | ||
| ip.del_var(ref) | ||
| break |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
How likely is it that the object is in user_ns? If it's only occasionally, can wrap this in:
if graphic in ip.user_ns.values(): ...
I guess it's possible that the graphic is present more than once, under a different name?
Alt solution that might be faster because it avoids copying the keys and looking up the values:
keys_to_delete = [] for key, ob in ip.user_ns.items(): if ob is graphic: keys_to_delete.append(key) for key in keys_to_delete: ip.del_var(key)
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
How likely is it that the object is in
user_ns? If it's only occasionally, can wrap this in:if graphic in ip.user_ns.values(): ...
in operators don't work if any item of the iterable is a numpy array, for example:
a = np.random.rand(10) l = [a, "bah", 123] # will raise a ValueError 123 in l
I've resorted to this, couldn't think of a more performance solution. Time taken scales with the number of items in the namespace.
if IS_IPYTHON: # remove any references that ipython might have made ip = get_ipython() # check both namespaces for namespace in [ip.user_ns, ip.user_ns_hidden]: # find the reference for ref, obj in namespace.items(): if graphic is obj: # we found the reference, remove from ipython ip.del_var(ref) break
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
No problems with deleting items from an object being iterated over? I guess it depends on IPython internals whether that'd be a problem.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
LGTM aside from the minor suggestions that Almar had
I think this will be super useful for users to get the actual object instead of a weakref back (less confusing when interacting with objects etc.). I agree that for now we just leave weakref to the world object...we can always change later.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
ready for another look, sorry for the delay been sick 🤧 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Hope you get better soon! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
@clewis7 ready to go! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
use of weakref.proxy GraphicCollection.__del__ method can cause confusing tracebacks Create a Proxy subclass that we use for our Graphic classes
There was an error while loading. Please reload this page.