472,951 Members | 2,056 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,951 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 3849
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

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

Similar topics

8
by: simon place | last post by:
Spent some very frustrating hours recoding to find a way of closing a server socket, i'd not thought it would be any problem, however, after complete failure and as a last resort, i looked at the...
4
by: dustin lee | last post by:
Over the years I've gotten out of the habit of explicitly closing file objects (whether for reading or writing) since the right thing always seems to happen auto-magically (e.g. files get written...
2
by: Michael Surette | last post by:
I have been trying to automate the changing of passwords using python and pexpect. I wrote a script as a test and it works, except that it gives me an exception when it stops running: Exception...
7
by: Tumurbaatar S. | last post by:
Is it so important to close database connections? As I understand, after processing a request and sending a response, page object destroyed. So all used connections also destroyed. Yes?
2
by: John Rossitter | last post by:
Hi Everyone, I have a windows service which consumes a web service on a separate machine in our network. I modified my machine.config to allow my service application to make 200 connections to...
5
by: funkyj | last post by:
I love pexpect because it means I may never have to use expect again (I don't do any heavy expect lifting -- I just need simple tty control)! As a python advocate I find it embarassing how...
14
by: cage | last post by:
hello can i write a eof to a file descriptor without closing it? like: fd.write(EOF) or something grts, ruben
0
by: Vishal Sethia | last post by:
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....
5
by: crybaby | last post by:
I need to ssh into a remote machine and check if mytest.log file is there. I have setup ssh keys to handle login authentications. How do I determine if mytest.log is there by using Pexpect. What...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...

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.