def run(self):

    # wait to accept a connection - set a short timeout so we can be interrupted if plans change
    self.socket.settimeout(1)
    debug("Socket about to accept")
    while self.socket is not None:
      try:
        self.conn, addr = self.socket.accept()
        self.conn.settimeout(None)  # Revert to no timeout once things are established
      except socket.error as msg:
        debug('Accept: ' + str(msg))
      else:
        debug('Socket accepted')
        break

    if self.socket is None:
      return

    # display client information
    debug('Connected with ' + addr[0] + ':' + str(addr[1]))

    self.initPUTComms()

    self.writeToPUT("STEP\n")

    data = self.readFromPUT()  # response like '200 OK'
    debug('data: ' + str(data))

    bpResponse = self.readFromPUT()  # response like '202 Paused /path/to/project/main.lua 3\n'
    debug('bpResponse: ' + bpResponse)

    bpMatches = re.search(r'^202 Paused\s+(.+?)\s+(\d+)$', bpResponse.strip())

    # Handle the response to the STEP command we just issued to start the PUT
    if bpMatches is not None:
      filename = bpMatches.group(1)
      line = bpMatches.group(2)

      debug("run: filename {0}, line {1}".format(filename, line))

      if not filename.endswith("main.lua"):  # we get a pause in "init.lua" if there's a syntax error in main.lua
        debugger_status("Error running main.lua")
        on_main_thread(lambda: sublime.error_message("There was an error running main.lua.\n\nCheck Console for error messages."))
        # self.writeToPUT("RUN\n") # this leaves the Simulator is a deterministic state
      else:
        debugger_status("Paused at line {0} of {1}".format(line, filename))
        on_main_thread(lambda: self.showSublimeContext(filename, int(line)))
    else:
      errMatches = re.search(r'^401 Error in Execution (\d+)$', bpResponse.strip())
      if errMatches is not None:
        size = errMatches.group(1)
        console_output("Error in remote application: ")
        console_output(self.readFromPUT(size))
      else:
        print("Corona Editor Error: ", bpResponse)
        on_main_thread(lambda: sublime.error_message("Unexpected response from Simulator:\n\n" + str(bpResponse) + "\n\nCheck Console for error messages."))

    # Restore any breakpoint we have saved (breakpoints can only be set when
    # we are running the debugger though we allow the user to think they are
    # setting breakpoints before it's started)
    on_main_thread(lambda: self.restore_breakpoints())

    self.doCommand('backtrace')
    # Skip displaying local variables on problematic releases (if we know what it is)
    if corona_sdk_version and ( int(corona_sdk_version) >= 2489 and int(corona_sdk_version) < 2517 ):
      variables_output("Local variable display disabled with this version of Corona SDK ("+corona_sdk_version+").  Try a build after 2515")
    else:
      self.doCommand('locals')

    while self.debugger_running:
      cmd = debuggerCmdQ.get()
      self.performCommand(cmd)
      debuggerCmdQ.task_done()

    # clean up on PUT termination
    on_main_thread(lambda: self.completionCallback(self.threadID))

    debug('CoronaDebuggerThread: ends')
dataset/ETHPy150Open coronalabs/CoronaSDK-SublimeText/debugger.py/CoronaDebuggerThread.run/original