def OnRun(self): """ just loop and write responses """ self.stopTrace() try: while True: try: try: cmd = self.cmdQueue.get(1, 0.1) except _queue.Empty: if self.killReceived: try: self.sock.shutdown(SHUT_WR) self.sock.close() except: pass return # break if queue is empty and killReceived else: continue except: # PydevdLog(0, 'Finishing debug communication...(1)') # when liberating the thread here, we could have errors because we were shutting down # but the thread was still not liberated return out = cmd.getOutgoing() if DebugInfoHolder.DEBUG_TRACE_LEVEL >= 1: out_message = "Sending cmd: " out_message += ID_TO_MEANING.get(out[:3], "UNKNOWN") out_message += " " out_message += out try: sys.stderr.write("%s\n" % (out_message,)) except: pass if IS_PY3K: out = bytearray(out, "utf-8") self.sock.send( out ) # TODO: this does not guarantee that all message are sent (and jython does not have a send all) if cmd.id == CMD_EXIT: break if time is None: break # interpreter shutdown time.sleep(self.timeout) except Exception: GlobalDebuggerHolder.globalDbg.FinishDebuggingSession() if DebugInfoHolder.DEBUG_TRACE_LEVEL >= 0: traceback.print_exc()
def OnRun(self): """ just loop and write responses """ self.stopTrace() try: while True: try: try: cmd = self.cmdQueue.get(1, 0.1) except _queue.Empty: if self.killReceived: try: self.sock.shutdown(SHUT_WR) self.sock.close() except: pass return #break if queue is empty and killReceived else: continue except: #PydevdLog(0, 'Finishing debug communication...(1)') #when liberating the thread here, we could have errors because we were shutting down #but the thread was still not liberated return out = cmd.getOutgoing() if DebugInfoHolder.DEBUG_TRACE_LEVEL >= 1: out_message = 'sending cmd: ' out_message += ID_TO_MEANING.get(out[:3], 'UNKNOWN') out_message += ' ' out_message += out try: sys.stderr.write('%s\n' % (out_message, )) except: pass if IS_PY3K: out = bytearray(out, 'utf-8') self.sock.send( out ) #TODO: this does not guarantee that all message are sent (and jython does not have a send all) if cmd.id == CMD_EXIT: break if time is None: break #interpreter shutdown time.sleep(self.timeout) except Exception: GlobalDebuggerHolder.globalDbg.FinishDebuggingSession() if DebugInfoHolder.DEBUG_TRACE_LEVEL >= 0: traceback.print_exc()
def StartClient(host, port): """ connects to a host/port """ PydevdLog(1, "Connecting to ", host, ":", str(port)) s = socket(AF_INET, SOCK_STREAM) MAX_TRIES = 3 i = 0 while i<MAX_TRIES: try: s.connect((host, port)) except: i+=1 time.sleep(0.2) continue PydevdLog(1, "Connected.") return s sys.stderr.write("Could not connect to %s: %s\n" % (host, port)) sys.stderr.flush() traceback.print_exc() sys.exit(1) #TODO: is it safe?
def run(self): time.sleep(0.1) def send(s, msg): if IS_PYTHON3K: s.send(bytearray(msg, 'utf-8')) else: s.send(msg) while self.lastMsg == None: if self.processMsgFunc != None: s = MSG_PROCESSING_PROGRESS % quote_plus(self.processMsgFunc()) sent = send(self.socket, s) else: sent = send(self.socket, MSG_PROCESSING) if sent == 0: sys.exit(0) #connection broken time.sleep(0.1) sent = send(self.socket, self.lastMsg) if sent == 0: sys.exit(0) #connection broken
finally: log.Clear() self.socket.close() self.ended = True sys.exit(0) # connection broken except SystemExit: raise # No need to log SystemExit error except: s = StringIO.StringIO() exc_info = sys.exc_info() traceback.print_exception(exc_info[0], exc_info[1], exc_info[2], limit=None, file=s) err = s.getvalue() dbg(SERVER_NAME + " received error: " + str(err), ERROR) raise if __name__ == "__main__": port = int(sys.argv[1]) # this is from where we want to receive messages. t = T(port) dbg(SERVER_NAME + " will start", INFO1) t.start() time.sleep(5) t.join()
else: def nativePath(path): return fullyNormalizePath(path) def fullyNormalizePath(path): '''fixes the path so that the format of the path really reflects the directories in the system ''' return os.path.normpath(path) if __name__ == '__main__': try: #just give some time to get the reading threads attached (just in case) time.sleep(0.1) except: pass try: executable = nativePath(sys.executable) except: executable = sys.executable if sys.platform == "cygwin" and not executable.endswith('.exe'): executable += '.exe' try: s = 'Version%s.%s' % (sys.version_info[0], sys.version_info[1]) except AttributeError: #older versions of python don't have version_info
def run(self): # Echo server program try: import _pydev_log log = _pydev_log.Log() dbg(SERVER_NAME + ' creating socket', INFO1) try: s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind((HOST, self.thisPort)) except: sys.stderr.write( 'Error connecting with parameters: host: %s port: %s\n' % (HOST, self.serverPort)) raise s.listen(1) #socket to receive messages. #we stay here until we are connected. #we only accept 1 client. #the exit message for the server is @@KILL_SERVER_END@@ dbg(SERVER_NAME + ' waiting for connection', INFO1) conn, addr = s.accept() time.sleep(0.5) #wait a little before connecting to JAVA server dbg(SERVER_NAME + ' waiting to java client', INFO1) #after being connected, create a socket as a client. self.connectToServer() dbg(SERVER_NAME + ' Connected by ' + str(addr), INFO1) while 1: data = '' returnMsg = '' keepAliveThread = KeepAliveThread(self.socket) while data.find(MSG_END) == -1: received = conn.recv(BUFFER_SIZE) if len(received) == 0: sys.exit(0) #ok, connection ended if IS_PYTHON3K: data = data + received.decode('utf-8') else: data = data + received try: try: if data.find(MSG_KILL_SERVER) != -1: dbg(SERVER_NAME + ' kill message received', INFO1) #break if we received kill message. self.ended = True sys.exit(0) dbg(SERVER_NAME + ' starting keep alive thread', INFO2) keepAliveThread.start() if data.find(MSG_PYTHONPATH) != -1: comps = [] for p in _sys_path: comps.append((p, ' ')) returnMsg = self.getCompletionsMessage(None, comps) else: data = data[:data.rfind(MSG_END)] if data.startswith(MSG_IMPORTS): data = data.replace(MSG_IMPORTS, '') data = unquote_plus(data) defFile, comps = importsTipper.GenerateTip( data, log) returnMsg = self.getCompletionsMessage( defFile, comps) elif data.startswith(MSG_CHANGE_PYTHONPATH): data = data.replace(MSG_CHANGE_PYTHONPATH, '') data = unquote_plus(data) ChangePythonPath(data) returnMsg = MSG_OK elif data.startswith(MSG_SEARCH): data = data.replace(MSG_SEARCH, '') data = unquote_plus(data) (f, line, col), foundAs = importsTipper.Search(data) returnMsg = self.getCompletionsMessage( f, [(line, col, foundAs)]) elif data.startswith(MSG_CHANGE_DIR): data = data.replace(MSG_CHANGE_DIR, '') data = unquote_plus(data) CompleteFromDir(data) returnMsg = MSG_OK elif data.startswith(MSG_BIKE): returnMsg = MSG_INVALID_REQUEST #No longer supported. else: returnMsg = MSG_INVALID_REQUEST except SystemExit: returnMsg = self.getCompletionsMessage( None, [('Exit:', 'SystemExit', '')]) keepAliveThread.lastMsg = returnMsg raise except: dbg(SERVER_NAME + ' exception occurred', ERROR) s = StringIO.StringIO() traceback.print_exc(file=s) err = s.getvalue() dbg(SERVER_NAME + ' received error: ' + str(err), ERROR) returnMsg = self.getCompletionsMessage( None, [('ERROR:', '%s\nLog:%s' % (err, log.GetContents()), '')]) finally: log.Clear() keepAliveThread.lastMsg = returnMsg conn.close() self.ended = True sys.exit(0) #connection broken except SystemExit: raise #No need to log SystemExit error except: s = StringIO.StringIO() exc_info = sys.exc_info() traceback.print_exception(exc_info[0], exc_info[1], exc_info[2], limit=None, file=s) err = s.getvalue() dbg(SERVER_NAME + ' received error: ' + str(err), ERROR) raise
sys.exit(0) #connection broken except SystemExit: raise #No need to log SystemExit error except: s = StringIO.StringIO() exc_info = sys.exc_info() traceback.print_exception(exc_info[0], exc_info[1], exc_info[2], limit=None, file=s) err = s.getvalue() dbg(SERVER_NAME + ' received error: ' + str(err), ERROR) raise if __name__ == '__main__': thisPort = int( sys.argv[1]) #this is from where we want to receive messages. serverPort = int(sys.argv[2]) #this is where we want to write messages. t = T(thisPort, serverPort) dbg(SERVER_NAME + ' will start', INFO1) t.start() time.sleep(5) t.join()
return retval.value else: def nativePath(path): return fullyNormalizePath(path) def fullyNormalizePath(path): '''fixes the path so that the format of the path really reflects the directories in the system ''' return os.path.normpath(path) if __name__ == '__main__': try: #just give some time to get the reading threads attached (just in case) time.sleep(0.1) except: pass try: executable = nativePath(sys.executable) except: executable = sys.executable if sys.platform == "cygwin" and not executable.endswith('.exe'): executable += '.exe' try: s = 'Version%s.%s' % (sys.version_info[0], sys.version_info[1]) except AttributeError:
def run(self): # Echo server program try: import _pydev_log log = _pydev_log.Log() dbg(SERVER_NAME + ' creating socket' , INFO1) try: s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind((HOST, self.thisPort)) except: sys.stderr.write('Error connecting with parameters: host: %s port: %s\n' % (HOST, self.serverPort)) raise s.listen(1) #socket to receive messages. #we stay here until we are connected. #we only accept 1 client. #the exit message for the server is @@KILL_SERVER_END@@ dbg(SERVER_NAME + ' waiting for connection' , INFO1) conn, addr = s.accept() time.sleep(0.5) #wait a little before connecting to JAVA server dbg(SERVER_NAME + ' waiting to java client' , INFO1) #after being connected, create a socket as a client. self.connectToServer() dbg(SERVER_NAME + ' Connected by ' + str(addr), INFO1) while 1: data = '' returnMsg = '' keepAliveThread = KeepAliveThread(self.socket) while data.find(MSG_END) == -1: received = conn.recv(BUFFER_SIZE) if len(received) == 0: sys.exit(0) #ok, connection ended if IS_PYTHON3K: data = data + received.decode('utf-8') else: data = data + received try: try: if data.find(MSG_KILL_SERVER) != -1: dbg(SERVER_NAME + ' kill message received', INFO1) #break if we received kill message. self.ended = True sys.exit(0) dbg(SERVER_NAME + ' starting keep alive thread', INFO2) keepAliveThread.start() if data.find(MSG_PYTHONPATH) != -1: comps = [] for p in _sys_path: comps.append((p, ' ')) returnMsg = self.getCompletionsMessage(None, comps) else: data = data[:data.rfind(MSG_END)] if data.startswith(MSG_IMPORTS): data = data.replace(MSG_IMPORTS, '') data = unquote_plus(data) defFile, comps = importsTipper.GenerateTip(data, log) returnMsg = self.getCompletionsMessage(defFile, comps) elif data.startswith(MSG_CHANGE_PYTHONPATH): data = data.replace(MSG_CHANGE_PYTHONPATH, '') data = unquote_plus(data) ChangePythonPath(data) returnMsg = MSG_OK elif data.startswith(MSG_SEARCH): data = data.replace(MSG_SEARCH, '') data = unquote_plus(data) (f, line, col), foundAs = importsTipper.Search(data) returnMsg = self.getCompletionsMessage(f, [(line, col, foundAs)]) elif data.startswith(MSG_CHANGE_DIR): data = data.replace(MSG_CHANGE_DIR, '') data = unquote_plus(data) CompleteFromDir(data) returnMsg = MSG_OK elif data.startswith(MSG_BIKE): returnMsg = MSG_INVALID_REQUEST #No longer supported. else: returnMsg = MSG_INVALID_REQUEST except SystemExit: returnMsg = self.getCompletionsMessage(None, [('Exit:', 'SystemExit', '')]) keepAliveThread.lastMsg = returnMsg raise except: dbg(SERVER_NAME + ' exception occurred', ERROR) s = StringIO.StringIO() traceback.print_exc(file=s) err = s.getvalue() dbg(SERVER_NAME + ' received error: ' + str(err), ERROR) returnMsg = self.getCompletionsMessage(None, [('ERROR:', '%s\nLog:%s' % (err, log.GetContents()), '')]) finally: log.Clear() keepAliveThread.lastMsg = returnMsg conn.close() self.ended = True sys.exit(0) #connection broken except SystemExit: raise #No need to log SystemExit error except: s = StringIO.StringIO() exc_info = sys.exc_info() traceback.print_exception(exc_info[0], exc_info[1], exc_info[2], limit=None, file=s) err = s.getvalue() dbg(SERVER_NAME + ' received error: ' + str(err), ERROR) raise