Fixed a wrong apostrophe
[python.git] / Lib / multiprocessing / dummy / connection.py
blob4f0a6805de1061b5025bba7af82435489ea22565
2 # Analogue of `multiprocessing.connection` which uses queues instead of sockets
4 # multiprocessing/dummy/connection.py
6 # Copyright (c) 2006-2008, R Oudkerk --- see COPYING.txt
9 __all__ = [ 'Client', 'Listener', 'Pipe' ]
11 from Queue import Queue
14 families = [None]
17 class Listener(object):
19 def __init__(self, address=None, family=None, backlog=1):
20 self._backlog_queue = Queue(backlog)
22 def accept(self):
23 return Connection(*self._backlog_queue.get())
25 def close(self):
26 self._backlog_queue = None
28 address = property(lambda self: self._backlog_queue)
31 def Client(address):
32 _in, _out = Queue(), Queue()
33 address.put((_out, _in))
34 return Connection(_in, _out)
37 def Pipe(duplex=True):
38 a, b = Queue(), Queue()
39 return Connection(a, b), Connection(b, a)
42 class Connection(object):
44 def __init__(self, _in, _out):
45 self._out = _out
46 self._in = _in
47 self.send = self.send_bytes = _out.put
48 self.recv = self.recv_bytes = _in.get
50 def poll(self, timeout=0.0):
51 if self._in.qsize() > 0:
52 return True
53 if timeout <= 0.0:
54 return False
55 self._in.not_empty.acquire()
56 self._in.not_empty.wait(timeout)
57 self._in.not_empty.release()
58 return self._in.qsize() > 0
60 def close(self):
61 pass