def w_make_pair(self): import _multiprocessing fd1, fd2 = self.socketpair() rhandle = _multiprocessing.Connection(fd1, writable=False) whandle = _multiprocessing.Connection(fd2, readable=False) self.connections.append(rhandle) self.connections.append(whandle) return rhandle, whandle
def test_pipe_recv(): fd1, fd2 = os.pipe() r = _multiprocessing.Connection(fd1, writable=False) w = _multiprocessing.Connection(fd2, readable=False) w.send('foo') w.send('bar') a = ipcpipe(r) b = take(2) result = runPipeline(a >> b) assert result == ['foo', 'bar']
def Pipe(duplex=True): if duplex: s1, s2 = socket.socketpair() s1.setblocking(True) s2.setblocking(True) c1 = _multiprocessing.Connection(os.dup(s1.fileno())) c2 = _multiprocessing.Connection(os.dup(s2.fileno())) s1.close() s2.close() else: fd1, fd2 = os.pipe() c1 = _multiprocessing.Connection(fd1, writable=False) c2 = _multiprocessing.Connection(fd2, readable=False) return (c1, c2)
def main(): global host # Connect to the executor, and start the listener. fd = int(os.environ.get('UIFUTURES_HOST_FD') or sys.argv[1]) conn = _multiprocessing.Connection(fd) conn.send(dict( type='handshake', pid=os.getpid(), )) host = Host(conn) app = QtGui.QApplication([]) app.setApplicationName('Futures Host') app.setWindowIcon(QtGui.QIcon(utils.icon('fatcow/road_sign'))) dialog = Dialog(host) host.start() dialog.show() exit(app.exec_())
def test_repr(self): import _multiprocessing c = _multiprocessing.Connection(1) assert repr(c) == '<read-write Connection, handle 1>' if hasattr(_multiprocessing, 'PipeConnection'): c = _multiprocessing.PipeConnection(1) assert repr(c) == '<read-write PipeConnection, handle 1>'
def accept(self): s, self._last_accepted = self._socket.accept() s.setblocking(True) fd = duplicate(s.fileno()) conn = _multiprocessing.Connection(fd) s.close() return conn
def SocketClient(address): """ Return a connection object connected to the socket given by `address` """ family = address_type(address) s = socket.socket(getattr(socket, family)) t = _init_timeout() while 1: try: s.connect(address) except socket.error as e: if e.args[0] != errno.ECONNREFUSED or _check_timeout(t): debug('failed to connect to address %s', address) raise time.sleep(0.01) else: break else: raise fd = duplicate(s.fileno()) conn = _multiprocessing.Connection(fd) s.close() return conn
def Pipe(duplex=True): ''' Returns pair of connection objects at either end of a pipe ''' if duplex: s1, s2 = socket.socketpair() c1 = _multiprocessing.Connection(os.dup(s1.fileno())) c2 = _multiprocessing.Connection(os.dup(s2.fileno())) s1.close() s2.close() else: fd1, fd2 = os.pipe() c1 = _multiprocessing.Connection(fd1, writable=False) c2 = _multiprocessing.Connection(fd2, readable=False) return c1, c2
def accept(self): s, self._last_accepted = self._socket.accept() # non-blocking sockets fix for issue 6056 s.settimeout(None) fd = duplicate(s.fileno()) conn = _multiprocessing.Connection(fd) s.close() return conn
def test_repr(self): import _multiprocessing, os fd = os.dup(1) # closed by Connection.__del__ c = _multiprocessing.Connection(fd) assert repr(c) == '<read-write Connection, handle %d>' % fd if hasattr(_multiprocessing, 'PipeConnection'): fd = os.dup(1) # closed by PipeConnection.__del__ c = _multiprocessing.PipeConnection(fd) assert repr(c) == '<read-write PipeConnection, handle %d>' % fd
def __init__(self, fd, writable=True, readable=True): self.real = _multiprocessing.Connection(fd, writable=writable, readable=readable) self.ptime = 0. self.uptime = 0. self.pbytes = 0 self.upbytes = 0 self.pobjs = 0 self.upobjs = 0
def test_pipe_close(): fd1, fd2 = os.pipe() r = _multiprocessing.Connection(fd1, writable=False) w = _multiprocessing.Connection(fd2, readable=False) w.send('foo') w.send('bar') w.close() @flowlet def consume(): await () await () a = ipcpipe(r) b = consume() pipe = a >> b runPipeline(pipe) assert r.closed
def Pipe(duplex=True): ''' Returns pair of connection objects at either end of a pipe ''' if duplex: s1, s2 = socket.socketpair() # _multiprocessing.Connection read/write semantics do not handle # non-blocking sockets correctly (issue 6056). This bug-fix # retains current behavior and allows for a default socket timeout s1.settimeout(None) s2.settimeout(None) c1 = _multiprocessing.Connection(os.dup(s1.fileno())) c2 = _multiprocessing.Connection(os.dup(s2.fileno())) s1.close() s2.close() else: fd1, fd2 = os.pipe() c1 = _multiprocessing.Connection(fd1, writable=False) c2 = _multiprocessing.Connection(fd2, readable=False) return c1, c2
def accept(self): while True: try: s, self._last_accepted = self._socket.accept() except socket.error as e: if e.args[0] != errno.EINTR: raise else: break fd = duplicate(s.fileno()) conn = _multiprocessing.Connection(fd) s.close() return conn
def main(): global _conn # Connect to the executor, and start the listener. fd = int(sys.argv[1]) _conn = conn = _multiprocessing.Connection(fd) conn.send(dict( type='handshake', pid=os.getpid(), )) try: process(conn) except Exception as e: conn.send( dict( type='exception', exception_name=type(e).__name__, exception_message=str(e), exception_traceback=traceback.format_exc(), package=pickle.dumps(dict(exception=e, ), protocol=-1), ))
def SocketClient(address): family = getattr(socket, address_type(address)) t = _init_timeout() while 1: s = socket.socket(family) s.setblocking(True) try: s.connect(address) except socket.error as e: s.close() if e.args[0] != errno.ECONNREFUSED or _check_timeout(t): debug('failed to connect to address %s', address) raise time.sleep(0.01) else: break else: raise fd = duplicate(s.fileno()) conn = _multiprocessing.Connection(fd) s.close() return conn
while 1: try: s.connect(address) except socket.error, e: if e.args[0] != errno.ECONNREFUSED: # connection refused debug('failed to connect to address %s', address) raise time.sleep(0.01) else: break else: raise fd = duplicate(s.fileno()) conn = _multiprocessing.Connection(fd) s.close() return conn # # Definitions for connections based on named pipes # if sys.platform == 'win32': class PipeListener(object): ''' Representation of a named pipe ''' def __init__(self, address, backlog=None):
def rebuild_connection(reduced_handle, readable, writable): handle = rebuild_handle(reduced_handle) return _multiprocessing.Connection(handle, readable=readable, writable=writable)
def __init__(self, handle, readable=True, writable=True): self._conn = _mp.Connection(handle, readable, writable)
def __init__(self, fd, writable=True, readable=True): self.real = _multiprocessing.Connection(fd, writable=writable, readable=readable)