'Connect a client to its kernel'

def connect_client_to_kernel(self, client):

    connection_file = client.connection_file
    stderr_file = client.stderr_file
    (km, kc) = self.create_kernel_manager_and_kernel_client(connection_file, stderr_file)
    if (is_string(km) and (kc is None)):
        client.shellwidget.kernel_manager = None
        client.show_kernel_error(km)
        return
    kc.started_channels.connect((lambda c=client: self.process_started(c)))
    kc.stopped_channels.connect((lambda c=client: self.process_finished(c)))
    kc.start_channels(shell=True, iopub=True)
    shellwidget = client.shellwidget
    shellwidget.kernel_manager = km
    shellwidget.kernel_client = kc
