Thread: [SQL-CVS] r1547 - SQLObject/branches/0.7-bugfix/sqlobject
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: <sub...@co...> - 2006-01-30 20:13:52
|
Author: phd Date: 2006-01-30 13:13:40 -0700 (Mon, 30 Jan 2006) New Revision: 1547 Modified: SQLObject/branches/0.7-bugfix/sqlobject/declarative.py Log: Applied the patch 1407684: object initialization threading issue. Modified: SQLObject/branches/0.7-bugfix/sqlobject/declarative.py =================================================================== --- SQLObject/branches/0.7-bugfix/sqlobject/declarative.py 2006-01-30 18:28:18 UTC (rev 1546) +++ SQLObject/branches/0.7-bugfix/sqlobject/declarative.py 2006-01-30 20:13:40 UTC (rev 1547) @@ -33,6 +33,7 @@ """ from __future__ import generators +import threading __all__ = ('classinstancemethod', 'DeclarativeMeta', 'Declarative') @@ -84,6 +85,19 @@ return ('<bound method %s.%s of %r>' % (self.type.__name__, self.func.func_name, self.obj)) +def threadSafeMethod(lock): + def decorator(fn): + def _wrapper(self, *args, **kwargs): + lock.acquire() + return_value = fn(self, *args, **kwargs) + lock.release() + return return_value + try: + _wrapper.func_name = fn.func_name + except TypeError: + pass + return _wrapper + return decorator class DeclarativeMeta(type): @@ -92,6 +106,9 @@ if new_attrs.has_key('__classinit__'): cls.__classinit__ = staticmethod(cls.__classinit__.im_func) cls.__classinit__(cls, new_attrs) + if new_attrs.has_key('__init__'): + lock = threading.RLock() + cls.__init__ = threadSafeMethod(lock)(cls.__init__) return cls class Declarative(object): |