diff options
| author | Georg Brandl <georg@python.org> | 2009-03-15 22:11:07 (GMT) | 
|---|---|---|
| committer | Georg Brandl <georg@python.org> | 2009-03-15 22:11:07 (GMT) | 
| commit | fc9ea97a18c2c25045b4cc993932702b30df239c (patch) | |
| tree | 0d7d5f4b6ab64027ddd7ee822d1cc3ec13443207 /Lib/Queue.py | |
| parent | 545a134916a32cbfddb3001642491d9466a71536 (diff) | |
| download | cpython-fc9ea97a18c2c25045b4cc993932702b30df239c.zip cpython-fc9ea97a18c2c25045b4cc993932702b30df239c.tar.gz cpython-fc9ea97a18c2c25045b4cc993932702b30df239c.tar.bz2  | |
Move the previously local import of threading to module level.
This is cleaner and avoids lockups in obscure cases where a Queue
is instantiated while the import lock is already held by another thread.
OKed by Tim Peters.
Diffstat (limited to 'Lib/Queue.py')
| -rw-r--r-- | Lib/Queue.py | 16 | 
1 files changed, 8 insertions, 8 deletions
diff --git a/Lib/Queue.py b/Lib/Queue.py index 773b680..2db8d76 100644 --- a/Lib/Queue.py +++ b/Lib/Queue.py @@ -1,6 +1,10 @@  """A multi-producer, multi-consumer queue."""  from time import time as _time +try: +    import threading as _threading +except ImportError: +    import dummy_threading as _threading  from collections import deque  import heapq @@ -20,26 +24,22 @@ class Queue:      If maxsize is <= 0, the queue size is infinite.      """      def __init__(self, maxsize=0): -        try: -            import threading -        except ImportError: -            import dummy_threading as threading          self.maxsize = maxsize          self._init(maxsize)          # mutex must be held whenever the queue is mutating.  All methods          # that acquire mutex must release it before returning.  mutex          # is shared between the three conditions, so acquiring and          # releasing the conditions also acquires and releases mutex. -        self.mutex = threading.Lock() +        self.mutex = _threading.Lock()          # Notify not_empty whenever an item is added to the queue; a          # thread waiting to get is notified then. -        self.not_empty = threading.Condition(self.mutex) +        self.not_empty = _threading.Condition(self.mutex)          # Notify not_full whenever an item is removed from the queue;          # a thread waiting to put is notified then. -        self.not_full = threading.Condition(self.mutex) +        self.not_full = _threading.Condition(self.mutex)          # Notify all_tasks_done whenever the number of unfinished tasks          # drops to zero; thread waiting to join() is notified to resume -        self.all_tasks_done = threading.Condition(self.mutex) +        self.all_tasks_done = _threading.Condition(self.mutex)          self.unfinished_tasks = 0      def task_done(self):  | 
