Need help with strange segfault

Mitko Haralanov mitko at qlogic.com
Wed Sep 5 18:58:20 EDT 2007


I am attempting to get a working wrapper around the TransactionSet
class from the rpm module but I am getting unexplained segfaults
in /usr/bin/python.

The reason why I am working on a wrapper is that I want to have a
single RPM abstraction module which is thread-safe and does not tie up
the RPM database. So here is my wrapper class:

class Transaction:
    def __init__ (self, db=None):
        self.ts = None
        self.ts_lock = Lock ()
        self.db = db
        self.func = None

    # This method will acquire the lock, record the TransactionSet
    # method being called by the caller and return the pointer to
    # the call_ts_func () function, which will do all the work.
    def __getattr__ (self, name):
	self.ts_lock.acquire ()
        self.func = name
        return self.call_ts_func

    # This method serves as a wrapper around the actual TransactionSet
    # method being called. It will open the database, call the
    # TransactionSet method, close the databse, and then release the
    # lock acquired in the __getattr__ () function.
    def call_ts_func (self, *args):
        if not self.ts:
            if self.db: rpm.addMacro ("_dbpath", self.db)
            self.ts = rpm.TransactionSet ()
            self.ts.openDB ()
            if self.db: rpm.delMacro ("_dbpath")

        func = self.ts.__getattribute__ (self.func)
        rs = func (*args)

        self.func = None
        self.ts.clean ()
        self.ts.closeDB ()
        del self.ts
        self.ts = None
        self.ts_lock.release ()
        return rs

I am getting what appears to be a correct value in rs but as soon as I
try to access it from the caller function, Python segfaults.

Any help would be appreciated?

-- 
Mitko Haralanov					 mitko at qlogic.com
Senior Software Engineer			     650.934.8064
System Interconnect Group		    http://www.qlogic.com

==========================================
Any programming language is at its best before it is implemented and
used.



More information about the Python-list mailing list