Custom Search

Tuesday, November 23, 2010

Python synchronized method example

Python synchronized method example

import threading
class A:
    def __init__(def):
            self._lock = threading.RLock()
        # or threading.Lock(), if no reentrancy needed.

    def some_method(self):
        self._lock.acquire()
        try:
            "do your business"
        finally:
            self._lock.release()

No comments:

Post a Comment