ยปCore Development>Code coverage>Lib/multiprocessing/dummy/connection.py

Python code coverage for Lib/multiprocessing/dummy/connection.py

#countcontent
1n/a#
2n/a# Analogue of `multiprocessing.connection` which uses queues instead of sockets
3n/a#
4n/a# multiprocessing/dummy/connection.py
5n/a#
6n/a# Copyright (c) 2006-2008, R Oudkerk
7n/a# Licensed to PSF under a Contributor Agreement.
8n/a#
9n/a
10n/a__all__ = [ 'Client', 'Listener', 'Pipe' ]
11n/a
12n/afrom queue import Queue
13n/a
14n/a
15n/afamilies = [None]
16n/a
17n/a
18n/aclass Listener(object):
19n/a
20n/a def __init__(self, address=None, family=None, backlog=1):
21n/a self._backlog_queue = Queue(backlog)
22n/a
23n/a def accept(self):
24n/a return Connection(*self._backlog_queue.get())
25n/a
26n/a def close(self):
27n/a self._backlog_queue = None
28n/a
29n/a address = property(lambda self: self._backlog_queue)
30n/a
31n/a def __enter__(self):
32n/a return self
33n/a
34n/a def __exit__(self, exc_type, exc_value, exc_tb):
35n/a self.close()
36n/a
37n/a
38n/adef Client(address):
39n/a _in, _out = Queue(), Queue()
40n/a address.put((_out, _in))
41n/a return Connection(_in, _out)
42n/a
43n/a
44n/adef Pipe(duplex=True):
45n/a a, b = Queue(), Queue()
46n/a return Connection(a, b), Connection(b, a)
47n/a
48n/a
49n/aclass Connection(object):
50n/a
51n/a def __init__(self, _in, _out):
52n/a self._out = _out
53n/a self._in = _in
54n/a self.send = self.send_bytes = _out.put
55n/a self.recv = self.recv_bytes = _in.get
56n/a
57n/a def poll(self, timeout=0.0):
58n/a if self._in.qsize() > 0:
59n/a return True
60n/a if timeout <= 0.0:
61n/a return False
62n/a with self._in.not_empty:
63n/a self._in.not_empty.wait(timeout)
64n/a return self._in.qsize() > 0
65n/a
66n/a def close(self):
67n/a pass
68n/a
69n/a def __enter__(self):
70n/a return self
71n/a
72n/a def __exit__(self, exc_type, exc_value, exc_tb):
73n/a self.close()