"""
from Thinking in Python, Bruce Eckel
http://mindview.net/Books/TIPython

Simple emulation of Java's 'synchronized'
keyword, from Peter Norvig.
"""

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)

# You can create your own self.mutex, or inherit
# from this class:
class Synchronization:
    def __init__(self):
        self.mutex = RLock()
#:~

@@ -174,16 +174,17 @@
  RLock%0A%0A
+%0A
 def sync
@@ -201,16 +201,17 @@
 ethod):%0A
+%0A
     def 
@@ -480,16 +480,17 @@
 turn f%0A%0A
+%0A
 def sync
@@ -675,18 +675,20 @@
 e(names)
+ 
 ==
+ 
 type('')
@@ -974,16 +974,44 @@
 d(val)%0A%0A
+%0Aclass Synchronization:%0A    
 # You ca
@@ -1050,18 +1050,16 @@
  inherit
-%0A#
  from th
@@ -1068,38 +1068,16 @@
  class:%0A
-class Synchronization:
 %0A    def
@@ -1126,8 +1126,4 @@
 k()%0A
-#:~%0A

make pep8 happy