Closing pexpect connections using threads

Vishal Sethia sethia.vishal at gmail.com
Wed Oct 3 17:45:49 EDT 2007


I am trying to write a multi-threaded program and use pexpect along
with it. All works fine until I try to close the connection handle.
That thread keeps waiting until the connection handle closes. It
actually never comes out of that command(connection_handle.close()).
If I manually kill it using kill command, the thread comes out and
quits otherwise it is in the wait state forever.

      def daemon(self):
              self.continue_hearbeats_lock.acquire()
              self.continue_heartbeats = True
              self.continue_hearbeats_lock.release()
              thrdHandshake = threading.Event()
             threading.Thread(target=self.RunTests,name='Run_Te  st_Thread')

             while self.continue_heartbeats:
                  pass
      def RunTests(self):
           self.createconnection()
           self.closeconnection()

      def closeconnection()
         self.log("Closing connection for device")
         self.connection_handle.close()


createconnection is a API which creates SSH connection to a remote machine.

And upon running, it hangs at this point
11:8:17:910 [DBG][CLEANUP]
11:8:17:910 [DBG]Closing Connection for device
<pexpect.spawn instance at 0xb7b373cc>


Any tips on what I am missing here?

Thanks,

-V



More information about the Python-list mailing list