port the queue change r70405
This commit is contained in:
parent
f07d0026da
commit
0ed52455b7
16
Lib/queue.py
16
Lib/queue.py
|
@ -1,6 +1,10 @@
|
||||||
"""A multi-producer, multi-consumer queue."""
|
"""A multi-producer, multi-consumer queue."""
|
||||||
|
|
||||||
from time import time as _time
|
from time import time as _time
|
||||||
|
try:
|
||||||
|
import threading as _threading
|
||||||
|
except ImportError:
|
||||||
|
import dummy_threading as _threading
|
||||||
from collections import deque
|
from collections import deque
|
||||||
import heapq
|
import heapq
|
||||||
|
|
||||||
|
@ -20,26 +24,22 @@ class Queue:
|
||||||
If maxsize is <= 0, the queue size is infinite.
|
If maxsize is <= 0, the queue size is infinite.
|
||||||
"""
|
"""
|
||||||
def __init__(self, maxsize=0):
|
def __init__(self, maxsize=0):
|
||||||
try:
|
|
||||||
import threading
|
|
||||||
except ImportError:
|
|
||||||
import dummy_threading as threading
|
|
||||||
self.maxsize = maxsize
|
self.maxsize = maxsize
|
||||||
self._init(maxsize)
|
self._init(maxsize)
|
||||||
# mutex must be held whenever the queue is mutating. All methods
|
# mutex must be held whenever the queue is mutating. All methods
|
||||||
# that acquire mutex must release it before returning. mutex
|
# that acquire mutex must release it before returning. mutex
|
||||||
# is shared between the three conditions, so acquiring and
|
# is shared between the three conditions, so acquiring and
|
||||||
# releasing the conditions also acquires and releases mutex.
|
# 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
|
# Notify not_empty whenever an item is added to the queue; a
|
||||||
# thread waiting to get is notified then.
|
# 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;
|
# Notify not_full whenever an item is removed from the queue;
|
||||||
# a thread waiting to put is notified then.
|
# 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
|
# Notify all_tasks_done whenever the number of unfinished tasks
|
||||||
# drops to zero; thread waiting to join() is notified to resume
|
# 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
|
self.unfinished_tasks = 0
|
||||||
|
|
||||||
def task_done(self):
|
def task_done(self):
|
||||||
|
|
Loading…
Reference in New Issue