Index: Lib/queue.py =================================================================== --- Lib/queue.py (revision 70204) +++ Lib/queue.py (working copy) @@ -3,6 +3,7 @@ from time import time as _time from collections import deque import heapq +import warnings __all__ = ['Empty', 'Full', 'Queue', 'PriorityQueue', 'LifoQueue'] @@ -92,6 +93,11 @@ def empty(self): """Return True if the queue is empty, False otherwise (not reliable!).""" + + warnings.warn("Queue.empty() is deprecated, and scheduled to be removed\ + in 3.2. Instead, use qsize() or catch a queue.Empty exception. ", + DeprecationWarning, stacklevel=2) + self.mutex.acquire() n = not self._qsize() self.mutex.release() @@ -99,6 +105,11 @@ def full(self): """Return True if the queue is full, False otherwise (not reliable!).""" + + warnings.warn("Queue.full() is deprecated, and scheduled to be removed\ + in 3.2. Instead, use qsize() or catch a queue.Empty exception. ", + DeprecationWarning, stacklevel=2) + self.mutex.acquire() n = 0 < self.maxsize == self._qsize() self.mutex.release() Index: Lib/multiprocessing/queues.py =================================================================== --- Lib/multiprocessing/queues.py (revision 70204) +++ Lib/multiprocessing/queues.py (working copy) @@ -14,6 +14,7 @@ import collections import time import atexit +import warnings import weakref from queue import Empty, Full @@ -113,9 +114,19 @@ return self._maxsize - self._sem._semlock._get_value() def empty(self): + + warnings.warn("Queue.empty() is deprecated, and scheduled to be removed\ + in 3.2. Instead, use qsize() or catch a queue.Empty exception. ", + DeprecationWarning, stacklevel=2) + return not self._poll() def full(self): + + warnings.warn("Queue.full() is deprecated, and scheduled to be removed\ + in 3.2. Instead, use qsize() or catch a queue.Empty exception. ", + DeprecationWarning, stacklevel=2) + return self._sem._semlock._is_zero() def get_nowait(self): @@ -320,6 +331,11 @@ self._make_methods() def empty(self): + + warnings.warn("Queue.empty() is deprecated, and scheduled to be removed\ + in 3.2. Instead, use qsize() or catch a queue.Empty exception. ", + DeprecationWarning, stacklevel=2) + return not self._reader.poll() def __getstate__(self): Index: Lib/test/test_multiprocessing.py =================================================================== --- Lib/test/test_multiprocessing.py (revision 70204) +++ Lib/test/test_multiprocessing.py (working copy) @@ -17,6 +17,7 @@ import socket import random import logging +import warnings # Work around broken sem_open implementations @@ -310,16 +311,16 @@ # def queue_empty(q): - if hasattr(q, 'empty'): - return q.empty() - else: - return q.qsize() == 0 + ''' + Helper method for this test suite to indicate an empty queue + ''' + return q.qsize() == 0 def queue_full(q, maxsize): - if hasattr(q, 'full'): - return q.full() - else: - return q.qsize() == maxsize + ''' + Helper method for this test suite to indicate a full queue + ''' + return q.qsize() == maxsize class _TestQueue(BaseTestCase): @@ -525,6 +526,26 @@ for p in workers: p.join() + + + def test_deprecated_warnings(self): + ''' + This test will test that the deprecated methods do, in fact, raise a + deprecation warning + ''' + + with warnings.catch_warnings(record=True) as w: + # Cause all warnings to always be triggered. + warnings.simplefilter("error") + + q = multiprocessing.queues.Queue() + self.assertRaises(DeprecationWarning, q.empty) + self.assertRaises(DeprecationWarning, q.full) + + q2 = multiprocessing.queues.JoinableQueue() + self.assertRaises(DeprecationWarning, q2.empty) + self.assertRaises(DeprecationWarning, q2.full) + # # Index: Lib/test/test_queue.py =================================================================== --- Lib/test/test_queue.py (revision 70204) +++ Lib/test/test_queue.py (working copy) @@ -2,10 +2,12 @@ # to ensure the Queue locks remain stable. import queue import sys +from test import support import threading import time import unittest -from test import support +import warnings + QUEUE_SIZE = 5 @@ -193,6 +195,18 @@ q = self.type2test(QUEUE_SIZE) self.simple_queue_test(q) self.simple_queue_test(q) + + + def test_deprecated_warnings(self): + + + with warnings.catch_warnings(record=True) as w: + # Cause all warnings to always be triggered. + warnings.simplefilter("error") + + q = queue.Queue() + self.assertRaises(DeprecationWarning, q.empty) + self.assertRaises(DeprecationWarning, q.full) class QueueTest(BaseQueueTest): Index: Misc/NEWS =================================================================== --- Misc/NEWS (revision 70204) +++ Misc/NEWS (working copy) @@ -13,6 +13,8 @@ ----------------- ======= +- #Issue 5420: A deprecation warning has been added to Queue.empty() and + Queue.full(), plus all multiprocessing queue classes - The io module has been reimplemented in C for speed. Index: Tools/webchecker/wsgui.py =================================================================== --- Tools/webchecker/wsgui.py (revision 70204) +++ Tools/webchecker/wsgui.py (working copy) @@ -124,7 +124,7 @@ self.status_label.config(text=text) def check_msgq(self): - while not self.msgq.empty(): + while self.msgq.qsize() != 0: msg = self.msgq.get() if msg is None: self.go_button.configure(state=NORMAL)