471,338 Members | 1,036 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,338 software developers and data experts.

Closing pexpect connections in threads

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. If I manually kill it using kill command, the thread comes out and quits otherwise it is in the wait state forever.

Expand|Select|Wrap|Line Numbers
  1.  def daemon(self):
  2.         self.continue_hearbeats_lock.acquire()
  3.         self.continue_heartbeats = True
  4.         self.continue_hearbeats_lock.release()
  5.         thrdHandshake = threading.Event()
  6.  
  7.        threading.Thread(target=self.RunTests,name='Run_Test_Thread')
  8.        while self.continue_heartbeats:
  9.             pass 
  10.  
  11. def RunTests(self):
  12.      self.createconnection() 
  13.      self.closeconnection() 
  14.  
  15. def closeconnection()
  16.    self.log("Closign connection for device")
  17.    self.connection_handle.close() 
  18.  
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?
Oct 3 '07 #1
4 3620
Any hints yet or do you think I am missing something ?

I tried the same program with fork and it seemed to work fine. So If fork is my only hope then what modules do I need to use for communication between multiple processes within the same program. Is sub-processes a good bet ?

Thanks.
Oct 4 '07 #2
bartonc
6,596 Expert 4TB
Any hints yet or do you think I am missing something ?

I tried the same program with fork and it seemed to work fine. So If fork is my only hope then what modules do I need to use for communication between multiple processes within the same program. Is sub-processes a good bet ?

Thanks.
Sorry. I haven't had time to get to this one. I have some ideas, but currently have a deadline to meet. I'll try to get some time this afternoon.
Oct 4 '07 #3
Thanks barton.

Ok I have come up with one solution which is definitely not elegant. Just wanted to share with the experts and get their opinions.

Whenever I create a pexpect session, I get the PID of that session and store it in a global list. The parent function which initializes all the threads waits until all the threads are finished and then it grabs the global list and starts killing them using the <kill -9 pid>

Any better solutions ?
Oct 5 '07 #4
bartonc
6,596 Expert 4TB
Thanks barton.

Ok I have come up with one solution which is definitely not elegant. Just wanted to share with the experts and get their opinions.

Whenever I create a pexpect session, I get the PID of that session and store it in a global list. The parent function which initializes all the threads waits until all the threads are finished and then it grabs the global list and starts killing them using the <kill -9 pid>

Any better solutions ?
Sounds reasonable to me. I guess that the methods discussed in this thread don't apply to your pexpect situation?
Oct 5 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

8 posts views Thread by simon place | last post: by
4 posts views Thread by dustin lee | last post: by
2 posts views Thread by Michael Surette | last post: by
7 posts views Thread by Tumurbaatar S. | last post: by
14 posts views Thread by cage | last post: by
reply views Thread by Vishal Sethia | last post: by
5 posts views Thread by crybaby | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.