473,805 Members | 2,034 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Closing pexpect connections in threads

6 New Member
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.spaw n instance at 0xb7b373cc>


Any tips on what I am missing here?
Oct 3 '07 #1
4 3919
indianteam
6 New Member
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 Recognized Expert Expert
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
indianteam
6 New Member
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 Recognized Expert Expert
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
9290
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 python wrapper module for sockets, and found that the close command doesn't actually call the underlying close! this didn't seem right, so i added it, and my code now works simply and as expected. def close(self):
4
2592
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 to disk with no missing data). I've recently started do the same thing with database connections. I'm wondering if anyone has had trouble with this sort of "lazy" programming style. My assumption is the the database connection will get closed...
2
5347
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 exceptions.OSError: (10, 'No child processes') in <bound method spawn.__del__ of <pexpect.spawn instance at 0x403d938c>> ignored What is happening and how do I get rid of the exception?
7
1807
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
2104
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 the server at once, and I spool up to 200 threads at once to make calls to the server. All of this works great and as expected. However I have noticed that by default the underlying connections tend to stay open for about 90 seconds after my web...
5
4532
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 difficult it is do the following in python (without pexpect): - logon to a remote system using ssh - do an 'ls' and exit the remote shell - print the output from the remote shell session.
14
17232
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
1482
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. 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):...
5
8638
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 I have done so far is spawned a child for ssh. 1) Now what do I do to execute shell_cmd(ls and grep), spawn another child? 2) Can I use the same child that was spawned for ssh, if so how?
0
9716
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9596
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10356
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10361
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9179
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7644
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5676
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4316
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3006
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.