hi,
i'm having some issues with memory
even with the weakref stuff. i have
a feeling there must be better solutions,
but for now i've given myself a manual
way of clearing out the identity_map.
i think i have the checks to make sure
that it's okay to clear the id correct,
but i'm not so sure. in any case, i don't
know if it would be of interest to anyone
else, but the patch is below.
(i'm also including a small corner-case
patch for the task dump; and afaict the
mapper->mapping change is not yet in?)
d
---
Index: objectstore.py
===================================================================
--- objectstore.py (revision 841)
+++ objectstore.py (working copy)
@@ -73,6 +73,14 @@
current mapped object instances, as they are no longer in the
Identity Map."""
uow.set(UnitOfWork())
+def clear_object(*objs):
+ uow_ = uow()
+ for obj in objs:
+ uow_.clear_object(obj)
+
+def clear_class(*class_):
+ uow().clear_class(*class_)
+
def delete(*obj):
"""registers the given objects as to be deleted upon the next
commit"""
uw = uow()
@@ -159,7 +167,7 @@
self.parent = parent
def get(self, class_, *id):
- return sqlalchemy.mapper.object_mapper(class_).get(*id)
+ return sqlalchemy.mapping.object_mapper(class_).get(*id)
def _get(self, key):
return self.identity_map[key]
@@ -169,6 +177,25 @@
def has_key(self, key):
return self.identity_map.has_key(key)
+
+ def clear_object(self, obj):
+ # Make sure the object isn't new or dirty
+ if (obj in self.new or
+ obj in self.dirty):
+ raise ValueError('Object %s is either new or dirty -
cannot clear' % str(obj))
+ if hasattr(obj, "_instance_key"):
+ try:
+ del self.identity_map[obj._instance_key]
+ except KeyError:
+ pass
+
+ def clear_class(self, *class_):
+ # Don't know how to do this more efficiently.
+ for (key, obj) in self.identity_map.items():
+ # Based on knowledge of what get_id_key returns
+ # we know key[0] is the class of the object.
+ if key[0] in class_:
+ self.clear_object(obj)
def _remove_deleted(self, obj):
if hasattr(obj, "_instance_key"):
@@ -396,7 +432,10 @@
head = self._sort_dependencies()
if LOG or echo:
- print "Task dump:\n" + head.dump()
+ if head is None:
+ print 'Task dump: (No Task)'
+ else:
+ print "Task dump:\n" + head.dump()
if head is not None:
head.execute(self)
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
Sqlalchemy-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users