473,397 Members | 1,974 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 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 3889
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.