
from threading import RLock


def synchronized(method):

    def f(*args):
        self = args[0]
        self.mutex.acquire()
        # print method.__name__, 'acquired'
        try:
            return apply(method, args)
        finally:
            self.mutex.release()
            # print method.__name__, 'released'
    return f


def synchronize(klass, names=None):
    """Synchronize methods in the given class.
    Only synchronize the methods whose names are
    given, or all methods if names=None."""
    if type(names) == type(''):
            names = names.split()
    for (name, val) in klass.__dict__.items():
        if callable(val) and name != '__init__' and \
            (names == None or name in names):
                # print "synchronizing", name
                klass.__dict__[name] = synchronized(val)


class Synchronization:
    # You can create your own self.mutex, or inherit from this class:

    def __init__(self):
        self.mutex = RLock()


from threading import RLock


def synchronized(method):

    def f(*args):
        self = args[0]
        self.mutex.acquire()
        # print method.__name__, 'acquired'
        try:
            return apply(method, args)
        finally:
            self.mutex.release()
            # print method.__name__, 'released'
    return f


def synchronize(klass, names=None):
    """Synchronize methods in the given class.
    Only synchronize the methods whose names are
    given, or all methods if names=None."""
    if type(names) == type(''):
            names = names.split()
    for (name, val) in klass.__dict__.items():
        if callable(val) and name != '__init__' and \
            (names == None or name in names):
                # print "synchronizing", name
                setattr(klass, name, synchronized(val))


class Synchronization(object):
    # You can create your own self.mutex, or inherit from this class:

    def __init__(self):
        self.mutex = RLock()

Use setattr() instead of a direct access to __dict__
Use setattr() instead of a direct access to __dict__

Closes Feature Request 3110077 "new style classes"
https://sourceforge.net/tracker/?func=detail&aid=3110077&group_id=196342&atid=957075

  
  from threading import RLock
  
  
  def synchronized(method):
  
      def f(*args):
          self = args[0]
          self.mutex.acquire()
          # print method.__name__, 'acquired'
          try:
              return apply(method, args)
          finally:
              self.mutex.release()
              # print method.__name__, 'released'
      return f
  
  
  def synchronize(klass, names=None):
      """Synchronize methods in the given class.
      Only synchronize the methods whose names are
      given, or all methods if names=None."""
      if type(names) == type(''):
              names = names.split()
      for (name, val) in klass.__dict__.items():
          if callable(val) and name != '__init__' and \
              (names == None or name in names):
                  # print "synchronizing", name
-                 klass.__dict__[name] = synchronized(val)
+                 setattr(klass, name, synchronized(val))
  
  
- class Synchronization:
+ class Synchronization(object):
      # You can create your own self.mutex, or inherit from this class:
  
      def __init__(self):
          self.mutex = RLock()
  
Use setattr() instead of a direct access to __dict__
## Code Before:

from threading import RLock


def synchronized(method):

    def f(*args):
        self = args[0]
        self.mutex.acquire()
        # print method.__name__, 'acquired'
        try:
            return apply(method, args)
        finally:
            self.mutex.release()
            # print method.__name__, 'released'
    return f


def synchronize(klass, names=None):
    """Synchronize methods in the given class.
    Only synchronize the methods whose names are
    given, or all methods if names=None."""
    if type(names) == type(''):
            names = names.split()
    for (name, val) in klass.__dict__.items():
        if callable(val) and name != '__init__' and \
            (names == None or name in names):
                # print "synchronizing", name
                klass.__dict__[name] = synchronized(val)


class Synchronization:
    # You can create your own self.mutex, or inherit from this class:

    def __init__(self):
        self.mutex = RLock()

## Instruction:
Use setattr() instead of a direct access to __dict__
## Code After:

from threading import RLock


def synchronized(method):

    def f(*args):
        self = args[0]
        self.mutex.acquire()
        # print method.__name__, 'acquired'
        try:
            return apply(method, args)
        finally:
            self.mutex.release()
            # print method.__name__, 'released'
    return f


def synchronize(klass, names=None):
    """Synchronize methods in the given class.
    Only synchronize the methods whose names are
    given, or all methods if names=None."""
    if type(names) == type(''):
            names = names.split()
    for (name, val) in klass.__dict__.items():
        if callable(val) and name != '__init__' and \
            (names == None or name in names):
                # print "synchronizing", name
                setattr(klass, name, synchronized(val))


class Synchronization(object):
    # You can create your own self.mutex, or inherit from this class:

    def __init__(self):
        self.mutex = RLock()
