def testServer(self): client_port, server_port = self.getFreeAddresses() class ServerThread(threading.Thread): def __init__(self, client_port, server_port): threading.Thread.__init__(self) self.client_port = client_port self.server_port = server_port def run(self): import pydev_localhost pydevconsole.StartServer(pydev_localhost.get_localhost(), self.server_port, self.client_port) server_thread = ServerThread(client_port, server_port) server_thread.setDaemon(True) server_thread.start() client_thread = self.startClientThread(client_port) #@UnusedVariable import time time.sleep(.3) #let's give it some time to start the threads import pydev_localhost server = xmlrpclib.Server( 'http://%s:%s' % (pydev_localhost.get_localhost(), server_port)) server.addExec('class Foo:') server.addExec(' pass') server.addExec('') server.addExec('foo = Foo()') server.addExec('a = %s()' % (raw_input_name, )) server.addExec('print (a)') self.assertEqual(['input_request'], sys.stdout.getvalue().split())
def __init__(self, notifications_queue, port, daemon=False): threading.Thread.__init__(self) self.setDaemon( daemon ) # If False, wait for all the notifications to be passed before exiting! self.finished = False self.notifications_queue = notifications_queue import pydev_localhost # It is necessary to specify an encoding, that matches # the encoding of all bytes-strings passed into an # XMLRPC call: "All 8-bit strings in the data structure are assumed to use the # packet encoding. Unicode strings are automatically converted, # where necessary." # Byte strings most likely come from file names. encoding = file_system_encoding if encoding == "mbcs": # Windos symbolic name for the system encoding CP_ACP. # We need to convert it into a encoding that is recognized by Java. # Unfortunately this is not always possible. You could use # GetCPInfoEx and get a name similar to "windows-1251". Then # you need a table to translate on a best effort basis. Much to complicated. # ISO-8859-1 is good enough. encoding = "ISO-8859-1" self.server = xmlrpclib.Server('http://%s:%s' % (pydev_localhost.get_localhost(), port), encoding=encoding)
def readline(self, *args, **kwargs): #Ok, callback into the client to get the new input server = xmlrpclib.Server('http://%s:%s' % (self.host, self.client_port)) requested_input = server.RequestInput() if not requested_input: return '\n' #Yes, a readline must return something (otherwise we can get an EOFError on the input() call). return requested_input
def run_client(job_id, port, verbosity, coverage_output_file, coverage_include): job_id = int(job_id) import pydev_localhost server = xmlrpclib.Server('http://%s:%s' % (pydev_localhost.get_localhost(), port)) server.lock = threading.Lock() server_comm = ServerComm(job_id, server) server_comm.start() try: server_facade = ServerFacade(server_comm.notifications_queue) import pydev_runfiles import pydev_runfiles_xml_rpc pydev_runfiles_xml_rpc.SetServer(server_facade) tests_to_run = [1] while tests_to_run: #Investigate: is it dangerous to use the same xmlrpclib server from different threads? #It seems it should be, as it creates a new connection for each request... server.lock.acquire() try: tests_to_run = server.GetTestsToRun(job_id) finally: server.lock.release() if not tests_to_run: break files_to_tests = {} for test in tests_to_run: filename_and_test = test.split('|') if len(filename_and_test) == 2: files_to_tests.setdefault(filename_and_test[0], []).append(filename_and_test[1]) configuration = pydev_runfiles.Configuration( '', verbosity, None, None, None, files_to_tests, 1, None, coverage_output_file=coverage_output_file, coverage_include=coverage_include, ) test_runner = pydev_runfiles.PydevTestRunner(configuration) sys.stdout.flush() test_runner.run_tests() except: traceback.print_exc() server_comm.notifications_queue.put_nowait(KillServer())
def __init__(self, notifications_queue, port): threading.Thread.__init__(self) self.setDaemon( False ) #Wait for all the notifications to be passed before exiting! self.finished = False self.notifications_queue = notifications_queue import pydev_localhost self.server = xmlrpclib.Server('http://%s:%s' % (pydev_localhost.get_localhost(), port))
def testServer(self): self.original_stdout = sys.stdout sys.stdout = StringIO() try: client_port, server_port = self.getFreeAddresses() class ServerThread(threading.Thread): def __init__(self, client_port, server_port): threading.Thread.__init__(self) self.client_port = client_port self.server_port = server_port def run(self): import pydev_localhost pydevconsole.StartServer(pydev_localhost.get_localhost(), self.server_port, self.client_port) server_thread = ServerThread(client_port, server_port) server_thread.setDaemon(True) server_thread.start() client_thread = self.startClientThread( client_port) #@UnusedVariable import time time.sleep(.3) #let's give it some time to start the threads sys.stdout = StringIO() import pydev_localhost server = xmlrpclib.Server( 'http://%s:%s' % (pydev_localhost.get_localhost(), server_port)) server.execLine('class Foo:') server.execLine(' pass') server.execLine('') server.execLine('foo = Foo()') server.execLine('a = %s()' % (raw_input_name, )) server.execLine('print (a)') initial = time.time() while not client_thread.requested_input: if time.time() - initial > 2: raise AssertionError( 'Did not get the return asked before the timeout.') time.sleep(.1) while ['input_request'] != sys.stdout.getvalue().split(): if time.time() - initial > 2: break time.sleep(.1) self.assertEqual(['input_request'], sys.stdout.getvalue().split()) finally: sys.stdout = self.original_stdout
def testServer(self): # Just making sure that the singleton is created in this thread. get_pydev_frontend(get_localhost(), 0) client_port, server_port = self.getFreeAddresses() class ServerThread(threading.Thread): def __init__(self, client_port, server_port): threading.Thread.__init__(self) self.client_port = client_port self.server_port = server_port def run(self): import pydev_localhost print('Starting server with:', pydev_localhost.get_localhost(), self.server_port, self.client_port) pydevconsole.StartServer(pydev_localhost.get_localhost(), self.server_port, self.client_port) server_thread = ServerThread(client_port, server_port) server_thread.setDaemon(True) server_thread.start() client_thread = self.startClientThread(client_port) #@UnusedVariable try: import time time.sleep(.3) #let's give it some time to start the threads import pydev_localhost server = xmlrpclib.Server( 'http://%s:%s' % (pydev_localhost.get_localhost(), server_port)) server.execLine( "import sys; print('Running with: %s %s' % (sys.executable or sys.platform, sys.version))" ) server.execLine('class Foo:') server.execLine(' pass') server.execLine('') server.execLine('foo = Foo()') server.execLine('a = %s()' % raw_input_name) initial = time.time() while not client_thread.requested_input: if time.time() - initial > 2: raise AssertionError( 'Did not get the return asked before the timeout.') time.sleep(.1) frame_xml = server.getFrame() self.assert_('RequestInput' in frame_xml, 'Did not fid RequestInput in:\n%s' % (frame_xml, )) finally: client_thread.shutdown()
def call_editor(self, filename, line=0, wait=True): """ Open an editor in PyDev """ if line is None: line = 0 # Make sure to send an absolution path because unlike most editor hooks # we don't launch a process. This is more like what happens in the zmqshell filename = os.path.abspath(filename) # Tell PyDev to open the editor server = xmlrpclib.Server('http://%s:%s' % (pydev_host, pydev_client_port)) server.OpenEditor(filename, line) if wait: raw_input("Press Enter when done editing:")
def call_editor(filename, line=0, wait=True): """ Open an editor in PyDev """ if line is None: line = 0 # Make sure to send an absolution path because unlike most editor hooks # we don't launch a process. This is more like what happens in the zmqshell filename = os.path.abspath(filename) # import sys # sys.__stderr__.write('Calling editor at: %s:%s\n' % (pydev_host, pydev_client_port)) # Tell PyDev to open the editor server = xmlrpclib.Server('http://%s:%s' % (pydev_host, pydev_client_port)) server.IPythonEditor(filename, str(line)) if wait: try: raw_input("Press Enter when done editing:") except NameError: input("Press Enter when done editing:")
def testServer(self): client_port, server_port = self.getFreeAddresses() class ServerThread(threading.Thread): def __init__(self, client_port, server_port): threading.Thread.__init__(self) self.client_port = client_port self.server_port = server_port def run(self): import pydev_localhost print('Starting server with:', pydev_localhost.get_localhost(), self.server_port, self.client_port) pydevconsole.StartServer(pydev_localhost.get_localhost(), self.server_port, self.client_port) server_thread = ServerThread(client_port, server_port) server_thread.setDaemon(True) server_thread.start() client_thread = self.startClientThread(client_port) #@UnusedVariable import time time.sleep(.3) #let's give it some time to start the threads import pydev_localhost server = xmlrpclib.Server( 'http://%s:%s' % (pydev_localhost.get_localhost(), server_port)) server.addExec( "import sys; print('Running with: %s %s' % (sys.executable or sys.platform, sys.version))" ) server.addExec('class Foo:') server.addExec(' pass') server.addExec('') server.addExec('foo = Foo()') server.addExec('a = %s()' % raw_input_name) server.addExec('print (a)')
def get_server(self): if getattr(self, 'host', None) is not None: return xmlrpclib.Server('http://%s:%s' % (self.host, self.client_port)) else: return None
def run_client(job_id, port, verbosity, coverage_output_file, coverage_include): job_id = int(job_id) import pydev_localhost server = xmlrpclib.Server('http://%s:%s' % (pydev_localhost.get_localhost(), port)) server.lock = threading.Lock() server_comm = ServerComm(job_id, server) server_comm.start() try: server_facade = ServerFacade(server_comm.notifications_queue) import pydev_runfiles import pydev_runfiles_xml_rpc pydev_runfiles_xml_rpc.SetServer(server_facade) #Starts None and when the 1st test is gotten, it's started (because a server may be initiated and terminated #before receiving any test -- which would mean a different process got all the tests to run). coverage = None try: tests_to_run = [1] while tests_to_run: #Investigate: is it dangerous to use the same xmlrpclib server from different threads? #It seems it should be, as it creates a new connection for each request... server.lock.acquire() try: tests_to_run = server.GetTestsToRun(job_id) finally: server.lock.release() if not tests_to_run: break if coverage is None: _coverage_files, coverage = StartCoverageSupportFromParams( None, coverage_output_file, 1, coverage_include) files_to_tests = {} for test in tests_to_run: filename_and_test = test.split('|') if len(filename_and_test) == 2: files_to_tests.setdefault(filename_and_test[0], []).append( filename_and_test[1]) configuration = pydev_runfiles.Configuration( '', verbosity, None, None, None, files_to_tests, 1, #Always single job here None, #The coverage is handled in this loop. coverage_output_file=None, coverage_include=None, ) test_runner = pydev_runfiles.PydevTestRunner(configuration) sys.stdout.flush() test_runner.run_tests(handle_coverage=False) finally: if coverage is not None: coverage.stop() coverage.save() except: traceback.print_exc() server_comm.notifications_queue.put_nowait(KillServer())