[Python-checkins] r60249 - python/trunk/Lib/threading.py
Brett Cannon
brett at python.org
Thu Jan 24 20:38:52 CET 2008
How bad was the performance hit? The code is so much cleaner with the
context managers.
-Brett
On Jan 24, 2008 10:12 AM, raymond.hettinger <python-checkins at python.org> wrote:
> Author: raymond.hettinger
> Date: Thu Jan 24 19:12:23 2008
> New Revision: 60249
>
> Modified:
> python/trunk/Lib/threading.py
> Log:
> Revert 60189 and restore performance.
>
> Modified: python/trunk/Lib/threading.py
> ==============================================================================
> --- python/trunk/Lib/threading.py (original)
> +++ python/trunk/Lib/threading.py Thu Jan 24 19:12:23 2008
> @@ -347,18 +347,27 @@
> return self.__flag
>
> def set(self):
> - with self.__cond:
> + self.__cond.acquire()
> + try:
> self.__flag = True
> self.__cond.notifyAll()
> + finally:
> + self.__cond.release()
>
> def clear(self):
> - with self.__cond:
> + self.__cond.acquire()
> + try:
> self.__flag = False
> + finally:
> + self.__cond.release()
>
> def wait(self, timeout=None):
> - with self.__cond:
> + self.__cond.acquire()
> + try:
> if not self.__flag:
> self.__cond.wait(timeout)
> + finally:
> + self.__cond.release()
>
> # Helper to generate new thread names
> _counter = 0
> @@ -525,9 +534,10 @@
> pass
>
> def __stop(self):
> - with self.__block:
> - self.__stopped = True
> - self.__block.notifyAll()
> + self.__block.acquire()
> + self.__stopped = True
> + self.__block.notifyAll()
> + self.__block.release()
>
> def __delete(self):
> "Remove current thread from the dict of currently running threads."
> @@ -553,12 +563,15 @@
> # since it isn't if dummy_threading is *not* being used then don't
> # hide the exception.
>
> - with _active_limbo_lock:
> + _active_limbo_lock.acquire()
> + try:
> try:
> del _active[_get_ident()]
> except KeyError:
> if 'dummy_threading' not in _sys.modules:
> raise
> + finally:
> + _active_limbo_lock.release()
>
> def join(self, timeout=None):
> if not self.__initialized:
> @@ -571,7 +584,8 @@
> if __debug__:
> if not self.__stopped:
> self._note("%s.join(): waiting until thread stops", self)
> - with self.__block:
> + self.__block.acquire()
> + try:
> if timeout is None:
> while not self.__stopped:
> self.__block.wait()
> @@ -589,6 +603,8 @@
> else:
> if __debug__:
> self._note("%s.join(): thread stopped", self)
> + finally:
> + self.__block.release()
>
> def getName(self):
> assert self.__initialized, "Thread.__init__() not called"
> _______________________________________________
> Python-checkins mailing list
> Python-checkins at python.org
> http://mail.python.org/mailman/listinfo/python-checkins
>
More information about the Python-checkins
mailing list