def start_socket(self, port=None): assert not hasattr(self, 'port'), 'Socket already initialized.' from _pydev_bundle.pydev_localhost import get_socket_name if SHOW_WRITES_AND_READS: print('start_socket') self._sequence = -1 if port is None: socket_name = get_socket_name(close=True) else: socket_name = (pydev_localhost.get_localhost(), port) server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) server_socket.bind(socket_name) self.port = socket_name[1] server_socket.listen(1) if SHOW_WRITES_AND_READS: print('Waiting in socket.accept()') self.server_socket = server_socket new_sock, addr = server_socket.accept() if SHOW_WRITES_AND_READS: print('Test Writer Thread Socket:', new_sock, addr) reader_thread = self.reader_thread = ReaderThread(new_sock) reader_thread.start() self.sock = new_sock # initial command is always the version self.write_version() self.log.append('start_socket') self.finished_initialization = True
def start_socket(self, port=None): from _pydev_bundle.pydev_localhost import get_socket_name if SHOW_WRITES_AND_READS: print('start_socket') if port is None: socket_name = get_socket_name(close=True) else: socket_name = (pydev_localhost.get_localhost(), port) s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind(socket_name) self.port = socket_name[1] s.listen(1) if SHOW_WRITES_AND_READS: print('Waiting in socket.accept()') self.server_socket = s new_sock, addr = s.accept() if SHOW_WRITES_AND_READS: print('Test Writer Thread Socket:', new_sock, addr) reader_thread = self.reader_thread = ReaderThread(new_sock) reader_thread.start() self.sock = new_sock self._sequence = -1 # initial command is always the version self.write_version() self.log.append('start_socket')
def start_socket(self, port=None): from _pydev_bundle.pydev_localhost import get_socket_name if SHOW_WRITES_AND_READS: print('start_socket') if port is None: socket_name = get_socket_name(close=True) else: socket_name = (pydev_localhost.get_localhost(), port) s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind(socket_name) self.port = socket_name[1] s.listen(1) if SHOW_WRITES_AND_READS: print('Waiting in socket.accept()') self.server_socket = s newSock, addr = s.accept() if SHOW_WRITES_AND_READS: print('Test Writer Thread Socket:', newSock, addr) reader_thread = self.reader_thread = ReaderThread(newSock) reader_thread.start() self.sock = newSock self._sequence = -1 # initial command is always the version self.write_version() self.log.append('start_socket')
def __init__(self): AbstractWriterThread.__init__(self) socket_name = get_socket_name(close=True) server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) server_socket.bind(socket_name) server_socket.listen(1) self.port = socket_name[1] self.__server_socket = server_socket
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
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.setDaemon(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
def _create_socket(port=None): if hasattr(_create_socket, '_used_ports'): assert port not in _create_socket._used_ports, 'Socket already initialized.' else: _create_socket._used_ports = set() if port is not None: _create_socket._used_ports.add(port) from _pydev_bundle.pydev_localhost import get_socket_name if SHOW_WRITES_AND_READS: print('start_socket') if port is None: socket_name = get_socket_name(close=True) else: socket_name = (pydev_localhost.get_localhost(), port) sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) sock.bind(socket_name) return sock
def start_socket(self, port=None): assert not hasattr(self, 'port'), 'Socket already initialized.' from _pydev_bundle.pydev_localhost import get_socket_name if SHOW_WRITES_AND_READS: print('start_socket') self._sequence = -1 if port is None: socket_name = get_socket_name(close=True) else: socket_name = (pydev_localhost.get_localhost(), port) server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) server_socket.bind(socket_name) self.port = socket_name[1] server_socket.listen(1) if SHOW_WRITES_AND_READS: print('Waiting in socket.accept()') self.server_socket = server_socket new_socket, addr = server_socket.accept() if SHOW_WRITES_AND_READS: print('Test Writer Thread Socket:', new_socket, addr) self._set_socket(new_socket)
except SystemExit: raise except: interpreter.showtraceback() else: pydevd_save_locals.save_locals(frame) return False #======================================================================================================================= # main #======================================================================================================================= if __name__ == '__main__': #Important: don't use this module directly as the __main__ module, rather, import itself as pydevconsole #so that we don't get multiple pydevconsole modules if it's executed directly (otherwise we'd have multiple #representations of its classes). #See: https://sw-brainwy.rhcloud.com/tracker/PyDev/446: #'Variables' and 'Expressions' views stopped working when debugging interactive console import pydevconsole sys.stdin = pydevconsole.BaseStdIn(sys.stdin) port, client_port = sys.argv[1:3] from _pydev_bundle import pydev_localhost if int(port) == 0 and int(client_port) == 0: (h, p) = pydev_localhost.get_socket_name() client_port = p pydevconsole.start_server(pydev_localhost.get_localhost(), int(port), int(client_port))
Exec(code, updated_globals, frame.f_locals) except SystemExit: raise except: interpreter.showtraceback() else: pydevd_save_locals.save_locals(frame) return False #======================================================================================================================= # main #======================================================================================================================= if __name__ == '__main__': #Important: don't use this module directly as the __main__ module, rather, import itself as pydevconsole #so that we don't get multiple pydevconsole modules if it's executed directly (otherwise we'd have multiple #representations of its classes). #See: https://sw-brainwy.rhcloud.com/tracker/PyDev/446: #'Variables' and 'Expressions' views stopped working when debugging interactive console import pydevconsole sys.stdin = pydevconsole.BaseStdIn(sys.stdin) port, client_port = sys.argv[1:3] from _pydev_bundle import pydev_localhost if int(port) == 0 and int(client_port) == 0: (h, p) = pydev_localhost.get_socket_name() client_port = p pydevconsole.start_server(pydev_localhost.get_localhost(), int(port), int(client_port))
def get_free_port(): from _pydev_bundle.pydev_localhost import get_socket_name return get_socket_name(close=True)[1]
def get_free_port(self): from _pydev_bundle.pydev_localhost import get_socket_name return get_socket_name(close=True)[1]