Mercurial > cpython-lru_cache-weakref
annotate Lib/idlelib/RemoteObjectBrowser.py @ 87690:66c1c9f32567 default tip
Add use_weakref option to functools.lru_cache
The use_weakref option makes lru_cache create weak references to the function
arguments when creating the cache key, which prevents them from staying in the
memory forever even after all other references to them are gone.
This is a proof of concept for http://bugs.python.org/issue19859
| author | Radomir Dopieralski <devel@sheep.art.pl> |
|---|---|
| date | Tue, 03 Dec 2013 16:02:48 +0100 |
| parents | bfa5835e10f0 |
| children |
| rev | line source |
|---|---|
|
42714
2ec16b6b4d04
Switch to absolute imports to support direct execution of modules. Many
Kurt B. Kaiser <kbk@shore.net>
parents:
42507
diff
changeset
|
1 from idlelib import rpc |
| 23547 | 2 |
| 3 def remote_object_tree_item(item): | |
| 4 wrapper = WrappedObjectTreeItem(item) | |
| 5 oid = id(wrapper) | |
| 6 rpc.objecttable[oid] = wrapper | |
| 7 return oid | |
| 8 | |
| 9 class WrappedObjectTreeItem: | |
| 10 # Lives in PYTHON subprocess | |
| 11 | |
| 12 def __init__(self, item): | |
| 13 self.__item = item | |
| 14 | |
| 15 def __getattr__(self, name): | |
| 16 value = getattr(self.__item, name) | |
| 17 return value | |
| 18 | |
| 19 def _GetSubList(self): | |
|
67816
bfa5835e10f0
#11069: fix the IDLE Stack Viewer, by not using "list" as a variable name.
Georg Brandl <georg@python.org>
parents:
42714
diff
changeset
|
20 sub_list = self.__item._GetSubList() |
|
bfa5835e10f0
#11069: fix the IDLE Stack Viewer, by not using "list" as a variable name.
Georg Brandl <georg@python.org>
parents:
42714
diff
changeset
|
21 return list(map(remote_object_tree_item, sub_list)) |
| 23547 | 22 |
| 23 class StubObjectTreeItem: | |
| 24 # Lives in IDLE process | |
| 25 | |
| 26 def __init__(self, sockio, oid): | |
| 27 self.sockio = sockio | |
| 28 self.oid = oid | |
| 29 | |
| 30 def __getattr__(self, name): | |
| 31 value = rpc.MethodProxy(self.sockio, self.oid, name) | |
| 32 return value | |
| 33 | |
| 34 def _GetSubList(self): | |
|
67816
bfa5835e10f0
#11069: fix the IDLE Stack Viewer, by not using "list" as a variable name.
Georg Brandl <georg@python.org>
parents:
42714
diff
changeset
|
35 sub_list = self.sockio.remotecall(self.oid, "_GetSubList", (), {}) |
|
bfa5835e10f0
#11069: fix the IDLE Stack Viewer, by not using "list" as a variable name.
Georg Brandl <georg@python.org>
parents:
42714
diff
changeset
|
36 return [StubObjectTreeItem(self.sockio, oid) for oid in sub_list] |
