~ubuntu-branches/ubuntu/precise/python3.2/precise-proposed

« back to all changes in this revision

Viewing changes to Lib/threading.py

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2012-03-09 18:40:39 UTC
  • mfrom: (30.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20120309184039-j3yk2emxr1plyo21
Tags: 3.2.3~rc1-1
* Python 3.2.3 release candidate 1.
* Update to 20120309 from the 3.2 branch.
* Fix libpython.a symlink. Closes: #660146.
* Build-depend on xauth.
* Run the gdb tests for the debug build only.

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 
6
6
from time import time as _time, sleep as _sleep
7
7
from traceback import format_exc as _format_exc
8
 
from collections import deque
9
8
from _weakrefset import WeakSet
10
9
 
11
10
# Note regarding PEP 8 compliant names
418
417
    def wait(self, timeout=None):
419
418
        self._cond.acquire()
420
419
        try:
421
 
            if not self._flag:
422
 
                self._cond.wait(timeout)
423
 
            return self._flag
 
420
            signaled = self._flag
 
421
            if not signaled:
 
422
                signaled = self._cond.wait(timeout)
 
423
            return signaled
424
424
        finally:
425
425
            self._cond.release()
426
426
 
435
435
# to be cyclic.  Threads are not allowed into it until it has fully drained
436
436
# since the previous cycle.  In addition, a 'resetting' state exists which is
437
437
# similar to 'draining' except that threads leave with a BrokenBarrierError,
438
 
# and a 'broken' state in which all threads get get the exception.
 
438
# and a 'broken' state in which all threads get the exception.
439
439
class Barrier(_Verbose):
440
440
    """
441
441
    Barrier.  Useful for synchronizing a fixed number of threads
1068
1068
    current = current_thread()
1069
1069
    with _active_limbo_lock:
1070
1070
        for thread in _active.values():
 
1071
            # Any lock/condition variable may be currently locked or in an
 
1072
            # invalid state, so we reinitialize them.
 
1073
            thread._reset_internal_locks()
1071
1074
            if thread is current:
1072
1075
                # There is only one active thread. We reset the ident to
1073
1076
                # its new value since it can have changed.
1074
1077
                ident = _get_ident()
1075
1078
                thread._ident = ident
1076
 
                # Any condition variables hanging off of the active thread may
1077
 
                # be in an invalid state, so we reinitialize them.
1078
 
                thread._reset_internal_locks()
1079
1079
                new_active[ident] = thread
1080
1080
            else:
1081
1081
                # All the others are already stopped.
1082
 
                # We don't call _Thread__stop() because it tries to acquire
1083
 
                # thread._Thread__block which could also have been held while
1084
 
                # we forked.
1085
 
                thread._stopped = True
 
1082
                thread._stop()
1086
1083
 
1087
1084
        _limbo.clear()
1088
1085
        _active.clear()