[mythtv] Python: collecting searchRecorded into list() has side effects

Jan mythtv at jd67.de
Fri Jul 26 10:32:45 UTC 2013


>>> QUESTIONS:
>>> Is it in general, a bad idea to store many (>40) Recorded objects 
>>> into a list()?

Answer myself: No. there is no problem storing recorded into a list()

>>>
>>> Is there any way to iterate a lot of Recorded in a sorted manner?

Answer myself: Recorded stored in a list() can sorted easily

> I did some debugging and it looks like that the new connections made 
> and STORED into DBDataRef._origdata by by deepcopy.
> Just for testing I cleared the _origdata and it works perfect.
>
> *** pseudo code 
> **************************************************************
> for i,r in enumerate( list(DB.searchRecorded(recgroup='Default')) ):
> print i, r.title, r.markup.getuncutlist()
> r.markup._origdata = None # WARNING: THIS IS NOT A FIX OR WORKAROUND
> ****
>

My current work arround:

for i,r in enumerate( list(DB.searchRecorded(recgroup='Default')) ):
# create ONE additional Recorded object and delete it after usage
r2 = MythTV.Recorded((r.chanid, r.starttime))
print i, r.title, r2.markup.getuncutlist()

****

Currently the classmethods DBDataRef.fromRaw and DBDataRef.fromCopy 
don't keep existing connections. I have no idea if this is wanted by 
design or not. I try a modification (patch below) and pass the DBCache 
object for reuse. It seams to work as expected.

Because I haven't a deep understanding of the architecture of 
myth-pyhton, I'm not sure about possible side effects.

Looking forward on your comments


=== PATCH ===


diff --git a/mythtv/bindings/python/MythTV/database.py 
b/mythtv/bindings/python/MythTV/database.py
index 525a213..a88c06a 100644
--- a/mythtv/bindings/python/MythTV/database.py
+++ b/mythtv/bindings/python/MythTV/database.py
@@ -500,14 +500,14 @@
for dat in other:
if dat not in self:
data.append(dat)
- return self.fromCopy(data)
+ return self.fromCopy(data, self._db)

def __and__(self, other):
data = []
for dat in self:
if dat in other:
data.append(dat)
- return self.fromCopy(data)
+ return self.fromCopy(data, self._db)

@classmethod
def _setClassDefs(cls, db=None):
@@ -556,26 +556,26 @@
self._origdata = self.deepcopy()

@classmethod
- def fromRaw(cls, data):
- c = cls('', bypass=True)
+ def fromRaw(cls, data, db=None):
+ c = cls('', db, bypass=True)
c._populated = True
for dat in data:
list.append(c, c.SubData(zip(self._datfields, row)))
return c

@classmethod
- def fromCopy(cls, data):
- c = cls('', bypass=True)
+ def fromCopy(cls, data, db=None):
+ c = cls('', db, bypass=True)
c._populated = True
for dat in data: list.append(c, dat)
return c

def copy(self):
if not self._populated: return []
- return self.fromCopy(self)
+ return self.fromCopy(self, self._db)
def deepcopy(self):
if not self._populated: return []
- return self.fromCopy([dat.copy() for dat in self])
+ return self.fromCopy([dat.copy() for dat in self], self._db)

def revert(self):
"""Delete all local changes to database."""

=== END OF PATCH ===


More information about the mythtv-dev mailing list