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
17 class Listener(object):
19 def __init__(self
, address
=None, family
=None, backlog
=1):
20 self
._backlog
_queue
= Queue(backlog
)
23 return Connection(*self
._backlog
_queue
.get())
26 self
._backlog
_queue
= None
28 address
= property(lambda self
: self
._backlog
_queue
)
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
):
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:
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