Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions
test.test_multiprocessing._TestQueue Class Reference
Inheritance diagram for test.test_multiprocessing._TestQueue:
Inheritance graph
[legend]
Collaboration diagram for test.test_multiprocessing._TestQueue:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def test_put
def test_get
def test_fork
def test_qsize
def test_task_done
def assertTimingAlmostEqual
def assertReturnsIfImplemented
def __reduce__

Public Attributes

_PyObject_HEAD_EXTRA Py_ssize_t ob_refcnt
struct _typeobjectob_type

Static Public Attributes

tuple ALLOWED_TYPES = ('processes', 'manager', 'threads')

Private Member Functions

def _test_put
def _test_get
def _test_fork
def _test_task_done

Detailed Description

Definition at line 353 of file test_multiprocessing.py.


Member Function Documentation

def test.test_multiprocessing.BaseTestCase.__reduce__ (   self,
  args 
) [inherited]

Definition at line 124 of file test_multiprocessing.py.

00124 
00125     def __reduce__(self, *args):
00126         raise NotImplementedError("shouldn't try to pickle a test case")

def test.test_multiprocessing._TestQueue._test_fork (   cls,
  queue 
) [private]

Definition at line 484 of file test_multiprocessing.py.

00484 
00485     def _test_fork(cls, queue):
00486         for i in range(10, 20):
00487             queue.put(i)
00488         # note that at this point the items may only be buffered, so the
00489         # process cannot shutdown until the feeder thread has finished
00490         # pushing items onto the pipe.

Here is the caller graph for this function:

def test.test_multiprocessing._TestQueue._test_get (   cls,
  queue,
  child_can_start,
  parent_can_continue 
) [private]

Definition at line 422 of file test_multiprocessing.py.

00422 
00423     def _test_get(cls, queue, child_can_start, parent_can_continue):
00424         child_can_start.wait()
00425         #queue.put(1)
00426         queue.put(2)
00427         queue.put(3)
00428         queue.put(4)
00429         queue.put(5)
00430         parent_can_continue.set()

Here is the caller graph for this function:

def test.test_multiprocessing._TestQueue._test_put (   cls,
  queue,
  child_can_start,
  parent_can_continue 
) [private]

Definition at line 357 of file test_multiprocessing.py.

00357 
00358     def _test_put(cls, queue, child_can_start, parent_can_continue):
00359         child_can_start.wait()
00360         for i in range(6):
00361             queue.get()
00362         parent_can_continue.set()

Here is the caller graph for this function:

def test.test_multiprocessing._TestQueue._test_task_done (   cls,
  q 
) [private]

Definition at line 533 of file test_multiprocessing.py.

00533 
00534     def _test_task_done(cls, q):
00535         for obj in iter(q.get, None):
00536             time.sleep(DELTA)
00537             q.task_done()

Here is the caller graph for this function:

def test.test_multiprocessing.BaseTestCase.assertReturnsIfImplemented (   self,
  value,
  func,
  args 
) [inherited]

Definition at line 114 of file test_multiprocessing.py.

00114 
00115     def assertReturnsIfImplemented(self, value, func, *args):
00116         try:
00117             res = func(*args)
00118         except NotImplementedError:
00119             pass
00120         else:
00121             return self.assertEqual(value, res)

Here is the call graph for this function:

Here is the caller graph for this function:

def test.test_multiprocessing.BaseTestCase.assertTimingAlmostEqual (   self,
  a,
  b 
) [inherited]

Definition at line 110 of file test_multiprocessing.py.

00110 
00111     def assertTimingAlmostEqual(self, a, b):
00112         if CHECK_TIMINGS:
00113             self.assertAlmostEqual(a, b, 1)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 491 of file test_multiprocessing.py.

00491 
00492     def test_fork(self):
00493         # Old versions of Queue would fail to create a new feeder
00494         # thread for a forked process if the original process had its
00495         # own feeder thread.  This test checks that this no longer
00496         # happens.
00497 
00498         queue = self.Queue()
00499 
00500         # put items on queue so that main process starts a feeder thread
00501         for i in range(10):
00502             queue.put(i)
00503 
00504         # wait to make sure thread starts before we fork a new process
00505         time.sleep(DELTA)
00506 
00507         # fork process
00508         p = self.Process(target=self._test_fork, args=(queue,))
00509         p.start()
00510 
00511         # check that all expected items are in the queue
00512         for i in range(20):
00513             self.assertEqual(queue.get(), i)
00514         self.assertRaises(pyqueue.Empty, queue.get, False)
00515 
00516         p.join()

Here is the call graph for this function:

Definition at line 431 of file test_multiprocessing.py.

00431 
00432     def test_get(self):
00433         queue = self.Queue()
00434         child_can_start = self.Event()
00435         parent_can_continue = self.Event()
00436 
00437         proc = self.Process(
00438             target=self._test_get,
00439             args=(queue, child_can_start, parent_can_continue)
00440             )
00441         proc.daemon = True
00442         proc.start()
00443 
00444         self.assertEqual(queue_empty(queue), True)
00445 
00446         child_can_start.set()
00447         parent_can_continue.wait()
00448 
00449         time.sleep(DELTA)
00450         self.assertEqual(queue_empty(queue), False)
00451 
00452         # Hangs unexpectedly, remove for now
00453         #self.assertEqual(queue.get(), 1)
00454         self.assertEqual(queue.get(True, None), 2)
00455         self.assertEqual(queue.get(True), 3)
00456         self.assertEqual(queue.get(timeout=1), 4)
00457         self.assertEqual(queue.get_nowait(), 5)
00458 
00459         self.assertEqual(queue_empty(queue), True)
00460 
00461         get = TimingWrapper(queue.get)
00462         get_nowait = TimingWrapper(queue.get_nowait)
00463 
00464         self.assertRaises(pyqueue.Empty, get, False)
00465         self.assertTimingAlmostEqual(get.elapsed, 0)
00466 
00467         self.assertRaises(pyqueue.Empty, get, False, None)
00468         self.assertTimingAlmostEqual(get.elapsed, 0)
00469 
00470         self.assertRaises(pyqueue.Empty, get_nowait)
00471         self.assertTimingAlmostEqual(get_nowait.elapsed, 0)
00472 
00473         self.assertRaises(pyqueue.Empty, get, True, TIMEOUT1)
00474         self.assertTimingAlmostEqual(get.elapsed, TIMEOUT1)
00475 
00476         self.assertRaises(pyqueue.Empty, get, False, TIMEOUT2)
00477         self.assertTimingAlmostEqual(get.elapsed, 0)
00478 
00479         self.assertRaises(pyqueue.Empty, get, timeout=TIMEOUT3)
00480         self.assertTimingAlmostEqual(get.elapsed, TIMEOUT3)
00481 
00482         proc.join()

Here is the call graph for this function:

Definition at line 363 of file test_multiprocessing.py.

00363 
00364     def test_put(self):
00365         MAXSIZE = 6
00366         queue = self.Queue(maxsize=MAXSIZE)
00367         child_can_start = self.Event()
00368         parent_can_continue = self.Event()
00369 
00370         proc = self.Process(
00371             target=self._test_put,
00372             args=(queue, child_can_start, parent_can_continue)
00373             )
00374         proc.daemon = True
00375         proc.start()
00376 
00377         self.assertEqual(queue_empty(queue), True)
00378         self.assertEqual(queue_full(queue, MAXSIZE), False)
00379 
00380         queue.put(1)
00381         queue.put(2, True)
00382         queue.put(3, True, None)
00383         queue.put(4, False)
00384         queue.put(5, False, None)
00385         queue.put_nowait(6)
00386 
00387         # the values may be in buffer but not yet in pipe so sleep a bit
00388         time.sleep(DELTA)
00389 
00390         self.assertEqual(queue_empty(queue), False)
00391         self.assertEqual(queue_full(queue, MAXSIZE), True)
00392 
00393         put = TimingWrapper(queue.put)
00394         put_nowait = TimingWrapper(queue.put_nowait)
00395 
00396         self.assertRaises(pyqueue.Full, put, 7, False)
00397         self.assertTimingAlmostEqual(put.elapsed, 0)
00398 
00399         self.assertRaises(pyqueue.Full, put, 7, False, None)
00400         self.assertTimingAlmostEqual(put.elapsed, 0)
00401 
00402         self.assertRaises(pyqueue.Full, put_nowait, 7)
00403         self.assertTimingAlmostEqual(put_nowait.elapsed, 0)
00404 
00405         self.assertRaises(pyqueue.Full, put, 7, True, TIMEOUT1)
00406         self.assertTimingAlmostEqual(put.elapsed, TIMEOUT1)
00407 
00408         self.assertRaises(pyqueue.Full, put, 7, False, TIMEOUT2)
00409         self.assertTimingAlmostEqual(put.elapsed, 0)
00410 
00411         self.assertRaises(pyqueue.Full, put, 7, True, timeout=TIMEOUT3)
00412         self.assertTimingAlmostEqual(put.elapsed, TIMEOUT3)
00413 
00414         child_can_start.set()
00415         parent_can_continue.wait()
00416 
00417         self.assertEqual(queue_empty(queue), True)
00418         self.assertEqual(queue_full(queue, MAXSIZE), False)
00419 
00420         proc.join()

Here is the call graph for this function:

Definition at line 517 of file test_multiprocessing.py.

00517 
00518     def test_qsize(self):
00519         q = self.Queue()
00520         try:
00521             self.assertEqual(q.qsize(), 0)
00522         except NotImplementedError:
00523             return
00524         q.put(1)
00525         self.assertEqual(q.qsize(), 1)
00526         q.put(5)
00527         self.assertEqual(q.qsize(), 2)
00528         q.get()
00529         self.assertEqual(q.qsize(), 1)
00530         q.get()
00531         self.assertEqual(q.qsize(), 0)

Here is the call graph for this function:

Definition at line 538 of file test_multiprocessing.py.

00538 
00539     def test_task_done(self):
00540         queue = self.JoinableQueue()
00541 
00542         if sys.version_info < (2, 5) and not hasattr(queue, 'task_done'):
00543             self.skipTest("requires 'queue.task_done()' method")
00544 
00545         workers = [self.Process(target=self._test_task_done, args=(queue,))
00546                    for i in range(4)]
00547 
00548         for p in workers:
00549             p.start()
00550 
00551         for i in range(10):
00552             queue.put(i)
00553 
00554         queue.join()
00555 
00556         for p in workers:
00557             queue.put(None)
00558 
00559         for p in workers:
00560             p.join()
00561 
00562 #
00563 #
00564 #

Here is the call graph for this function:


Member Data Documentation

tuple test.test_multiprocessing.BaseTestCase.ALLOWED_TYPES = ('processes', 'manager', 'threads') [static, inherited]

Definition at line 107 of file object.h.

struct _typeobject* _object::ob_type [inherited]

Definition at line 108 of file object.h.


The documentation for this class was generated from the following file: