コード例 #1
0
    kc.start_channels()

    # Ping the kernel
    msg_id = kc.kernel_info()
    try:
        reply = kc.get_shell_msg(timeout=1)
    except Empty:
        continue
    except Exception:
        traceback.print_exc()
    except KeyboardInterrupt:  # <C-c> or kill -SIGINT?
        sys.exit(0)
    else:
        connected = True
        # Set the socket on which to listen for messages
        socket = km.connect_iopub()
        print('IPython monitor connected successfully!')
    finally:
        if not connected:
            kc.stop_channels()

#------------------------------------------------------------------------------
#       Set stdout to desired tty
#------------------------------------------------------------------------------
term = ''
if len(sys.argv) > 1:
    # Set stdout to arbitrary file descriptor given as script argument
    #   $ python monitor.py '/dev/ttys003' &
    term = open(sys.argv[1], 'w')
    sys.stdout = term
else:
コード例 #2
0
ファイル: monitor.py プロジェクト: wilywampa/vim-ipython
        km.load_connection_file()

        kc = km.client()
        kc.start_channels()
        try:
            send = kc.execute
        except AttributeError:
            send = kc.shell_channel.execute
        if not hasattr(kc, 'iopub_channel'):
            kc.iopub_channel = kc.sub_channel

        send('', silent=True)
        try:
            msg = kc.shell_channel.get_msg(timeout=1)
            connected = True
            socket = km.connect_iopub()
            print('IPython monitor connected successfully')
            break
        except KeyboardInterrupt:
            sys.exit(0)
        except (Empty, KeyError):
            continue
        except Exception as e:
            import traceback
            traceback.print_exc()
        finally:
            if not connected:
                kc.stop_channels()


def colorize(string, color, bold=False, bright=False):