示例#1
0
def start_client(host, port):
    #replace exit (see comments on method)
    #note that this does not work in jython!!! (sys method can't be replaced).
    sys.exit = do_exit

    from pydev_console.pydev_protocol import PythonConsoleBackendService, PythonConsoleFrontendService

    enable_thrift_logging()

    client_service = PythonConsoleFrontendService

    client, server_transport = make_rpc_client(client_service, host, port)

    interpreter = InterpreterInterface(threading.currentThread(),
                                       rpc_client=client)

    # we do not need to start the server in a new thread because it does not need to accept a client connection, it already has it

    # Tell UMD the proper default namespace
    _set_globals_function(interpreter.get_namespace)

    server_service = PythonConsoleBackendService

    # `InterpreterInterface` implements all methods required for the handler
    server_handler = interpreter

    start_rpc_server(server_transport, server_service, server_handler)

    process_exec_queue(interpreter)
示例#2
0
    def test_server(self):
        self.original_stdout = sys.stdout
        sys.stdout = pydevd_io.IOBuf()
        try:
            from _pydev_bundle.pydev_localhost import get_socket_name
            host, port = get_socket_name(close=True)

            class ServerThread(threading.Thread):
                def __init__(self, backend_port):
                    threading.Thread.__init__(self)
                    self.backend_port = backend_port

                def run(self):
                    from _pydev_bundle import pydev_localhost
                    pydevconsole.start_server(self.backend_port)

            server_thread = ServerThread(port)
            server_thread.daemon = True
            server_thread.start()

            import time
            time.sleep(1)  #let's give it some time to start the threads

            rpc_client, server_transport = make_rpc_client(
                PythonConsoleBackendService, host, port)

            server_service = PythonConsoleFrontendService

            server_handler = self.create_frontend_handler()

            start_rpc_server(server_transport, server_service, server_handler)

            rpc_client.execLine('class Foo:')
            rpc_client.execLine('    pass')
            rpc_client.execLine('')
            rpc_client.execLine('foo = Foo()')
            rpc_client.execLine('a = %s()' % (raw_input_name, ))
            rpc_client.execLine('print (a)')
            initial = time.time()
            while not server_handler.requested_input:
                if time.time() - initial > 2:
                    raise AssertionError(
                        'Did not get the return asked before the timeout.')
                time.sleep(.1)

            found = sys.stdout.getvalue()
            while ['input_request'] != found.split():
                found += sys.stdout.getvalue()
                if time.time() - initial > 2:
                    break
                time.sleep(.1)
            self.assertIn('input_request', found.split())
        finally:
            sys.stdout = self.original_stdout