def remote_profile(script, argv, profiler_factory, interval, spawn, signum,
                   pickle_protocol, endpoint, verbose):
    """Launch a server to profile continuously.  The default endpoint is
    127.0.0.1:8912.
    """
    filename, code, globals_ = script
    sys.argv[:] = [filename] + list(argv)
    # create listener.
    listener = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    listener.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    listener.bind(endpoint)
    listener.listen(1)
    # be verbose or quiet.
    if verbose:
        log = lambda x: click.echo(click.style('> ', fg='cyan') + x)
        bound_addr = listener.getsockname()
        log('Listening on {0}:{1} for profiling...'.format(*bound_addr))
    else:
        log = noop
    # start profiling server.
    frame = sys._getframe()
    profiler = profiler_factory(base_frame=frame, base_code=code)
    profiler_trigger = BackgroundProfiler(profiler, signum)
    profiler_trigger.prepare()
    server_args = (interval, log, pickle_protocol)
    server = SelectProfilingServer(listener, profiler_trigger, *server_args)
    spawn(server.serve_forever)
    # exec the script.
    try:
        exec_(code, globals_)
    except KeyboardInterrupt:
        pass
def remote_profile ( script , argv , profiler_factory , interval , spawn , signum , pickle_protocol , endpoint , verbose ) : filename , code , globals_ = script sys . argv [ : ] = [ filename ] + list ( argv ) listener = socket . socket ( socket . AF_INET , socket . SOCK_STREAM ) listener . setsockopt ( socket . SOL_SOCKET , socket . SO_REUSEADDR , 1 ) listener . bind ( endpoint ) listener . listen ( 1 ) if verbose : log = lambda x : click . echo ( click . style ( '> ' , fg = 'cyan' ) + x ) bound_addr = listener . getsockname ( ) log ( 'Listening on {0}:{1} for profiling...' . format ( * bound_addr ) ) else : log = noop frame = sys . _getframe ( ) profiler = profiler_factory ( base_frame = frame , base_code = code ) profiler_trigger = BackgroundProfiler ( profiler , signum ) profiler_trigger . prepare ( ) server_args = ( interval , log , pickle_protocol ) server = SelectProfilingServer ( listener , profiler_trigger , * server_args ) spawn ( server . serve_forever ) try : exec_ ( code , globals_ ) except KeyboardInterrupt : pass
Launch a server to profile continuously.  The default endpoint is
    127.0.0.1:8912.