Connect to an IPython kernel as soon as its message is logged.
549991
def connect_to_ipykernel(self, service_name, timeout=10):
        """"""
        kernel_json_file = self.wait_for_ipykernel(service_name, timeout=10)
        self.start_interactive_mode()
        subprocess.check_call([
            sys.executable, "-m", "IPython", "console", "--existing", kernel_json_file
        ])
        self.stop_interactive_mode()
1371218
def dispatch_sockets(self, timeout=None):
        """"""
        for sock in self.select_sockets(timeout=timeout):
            if sock is self.listener:
                listener = sock
                sock, addr = listener.accept()
                self.connected(sock)
            else:
                try:
                    sock.recv(1)
                except socket.error as exc:
                    if exc.errno != ECONNRESET:
                        raise
                self.disconnected(sock)
1119941
def start_new_kernel(startup_timeout=60, kernel_name='python', **kwargs):
    """"""
    logger.debug('Starting new kernel: "%s"' % kernel_name)
    km = KernelManager(kernel_name=kernel_name,
                       kernel_spec_manager=NbvalKernelspecManager())
    km.start_kernel(**kwargs)
    kc = km.client()
    kc.start_channels()
    try:
        kc.wait_for_ready(timeout=startup_timeout)
    except RuntimeError:
        logger.exception('Failure starting kernel "%s"', kernel_name)
        kc.stop_channels()
        km.shutdown_kernel()
        raise

    return km, kc
146151
def connect(self, interface, event, handler):
        """"""
        object_path = self.object_path
        return self.bus.connect(interface, event, object_path, handler)
636242
def connect_async(self, conn_id, connection_string, callback):
        """"""

        future = self._loop.launch_coroutine(self._adapter.connect(conn_id, connection_string))
        future.add_done_callback(lambda x: self._callback_future(conn_id, x, callback))
335940
def listen(self, max_seconds=30):
        """"""
        if not self.connection:
            self.connect()
        start = time.time()
        conn, _, err = select([self.connection], [], [
                              self.connection], max_seconds)
        try:
            if len(err) > 0:
                raise socket.error("Couldn't open socket")
            message = b''
            while True:
                if time.time() - start > max_seconds:
                    raise socket.error(
                        "Timeout of %s seconds waiting for W&B process" % max_seconds)
                res = self.connection.recv(1024)
                term = res.find(b'\0')
                if term != -1:
                    message += res[:term]
                    break
                else:
                    message += res
            message = json.loads(message.decode('utf8'))
            if message['status'] == 'done':
                return True, None
            elif message['status'] == 'ready':
                return True, message
            elif message['status'] == 'launch_error':
                return False, None
            else:
                raise socket.error("Invalid status: %s" % message['status'])
        except (socket.error, ValueError) as e:
            util.sentry_exc(e)
            return False, None
1261911
def startLoop():
    
    def _ipython_loop_asyncio(kernel):
        '''
        Use asyncio event loop for the given IPython kernel.
        '''
        loop = asyncio.get_event_loop()

        def kernel_handler():
            kernel.do_one_iteration()
            loop.call_later(kernel._poll_interval, kernel_handler)

        loop.call_soon(kernel_handler)
        try:
            if not loop.is_running():
                loop.run_forever()
        finally:
            if not loop.is_running():
                loop.run_until_complete(loop.shutdown_asyncgens())
                loop.close()

    patchAsyncio()
    loop = asyncio.get_event_loop()
    if not loop.is_running():
        from ipykernel.eventloops import register_integration, enable_gui
        register_integration('asyncio')(_ipython_loop_asyncio)
        enable_gui('asyncio')
311050
def _connected(self, watcher, events):
        """"""
        self.connected = True
        self._finish()
        self.deferred.callback(self.sock)
748957
def _connected(self, sock):
        """"""
        logger.debug('socket connected, building protocol')
        self.protocol = self.factory.build(self.loop)
        self.connection = Connection(self.loop, self.sock, self.addr,
            self.protocol, self) 
        self.connector = None
        self.connect_deferred.callback(self.protocol)
1096300
def connect(*args, **kwargs):
    """"""
    kwargs['cursor_factory'] = TraceCursor
    conn = pg_connect(*args, **kwargs)
    return conn
998510
def connect(*args, **kwargs):
    """"""
    global __CONNECTION
    if __CONNECTION is None:
        __CONNECTION = Connection(*args, **kwargs)

    return __CONNECTION
1074316
def connect(cls, *args, **kwargs):
        
        loop = kwargs.get('loop')
        if loop is None:
            loop = trollius.get_event_loop()
        future = trollius.Future(loop=loop)

        def callback(arg):
            if not future.done():
                if isinstance(arg, Exception):
                    loop.call_soon_threadsafe(future.set_exception, arg)
                else:
                    loop.call_soon_threadsafe(future.set_result, arg)

        stream = cls(callback, *args, **kwargs)
        yield From(future)
        raise Return(stream)
209026
async def async_connect(self):
        """"""
        self._reader, self._writer = await asyncio.open_connection(
            self._host, self._port)

        with (await self._io_lock):
            try:
                await asyncio.wait_for(self._reader.readuntil(b'login: '), 9)
            except asyncio.streams.IncompleteReadError:
                _LOGGER.error(
                    "Unable to read from router on %s:%s" % (
                        self._host, self._port))
                return
            except TimeoutError:
                _LOGGER.error("Host timeout.")
            self._writer.write((self._username + '\n').encode('ascii'))
            await self._reader.readuntil(b'Password: ')

            self._writer.write((self._password + '\n').encode('ascii'))

            self._prompt_string = (await self._reader.readuntil(
                b'#')).split(b'\n')[-1]
        self._connected = True
166581
def connect(self):
        '''
        
        '''
        if self.connected:
            raise RuntimeError(
                '{} is connected already'.format(self.__class__.__name__))
        if self.closed:
            raise RuntimeError(
                '{} is closed already'.format(self.__class__.__name__))
        self.connected = True
        self._connect()
1123492
def connect(self, *args):
        """"""

        self.log("Connect ", args, lvl=verbose)

        try:
            sock = args[0]
            ip = args[1]

            if sock not in self._sockets:
                self.log("New client connected:", ip, lvl=debug)
                clientuuid = str(uuid4())
                self._sockets[sock] = Socket(ip, clientuuid)
                # Key uuid is temporary, until signin, will then be replaced
                #  with account uuid

                self._clients[clientuuid] = Client(
                    sock=sock,
                    ip=ip,
                    clientuuid=clientuuid,
                )

                self.log("Client connected:", clientuuid, lvl=debug)
            else:
                self.log("Old IP reconnected!", lvl=warn)
                #     self.fireEvent(write(sock, "Another client is
                # connecting from your IP!"))
                #     self._sockets[sock] = (ip, uuid.uuid4())
        except Exception as e:
            self.log("Error during connect: ", e, type(e), lvl=critical)
669837
def load_ipython_extension(ip, **kwargs):
    """"""
    global _loaded
    if not _loaded:
        ip.register_magics(MatlabMagics(ip, **kwargs))
        _loaded = True
92951
def _send(self, msg, buffers=None):
        """"""
        if self.comm is not None and self.comm.kernel is not None:
            self.comm.send(data=msg, buffers=buffers)