473,394 Members | 1,739 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,394 software developers and data experts.

pexpect: TIMEOUT exception never raised

I have a python script which uses pexpect and I want to timeout (i.e. raise
pexpect.TIMEOUT) if a long running command does not produce the output I am
expecting. To simulate the 'long running command', consider the following
example which simply runs the 'yes' command which prints an endless series
of 'y' characters to the terminal. I want to timeout after 10 seconds -:

child=pexpect.spawn('ssh me@remote_host')
child.sendline('yes')
child.expect([pexpect.TIMEOUT, "the pattern I'm expecting"],10)

In this situation, pexpect.TIMEOUT will never be raised. The TIMEOUT
exception is only raised if *no* output is received or the output has
completed and the pattern expected is not matched within the timeout
period. But what about situations where a command produces an infinite
amount of output? In the above example, the child.expect statement will
hang forever.

I thought about using signal.signal to set an alarm that fires a few seconds
after timeout and explicitly closes the session. However, my application
is multi-threaded (i.e. each thread respresents a connection to a remote
host) and signals can not be used outside the main thread :-(

Any ideas?

Cheers.
Adrian Casey.
Jul 19 '05 #1
0 1906

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Gianluca Trombetta | last post by:
Someone know pexpect module? I've a problem working with it... I need to run some commands on remote hosts, like ls, df -k etc..All right. Although, when i launch a command that have a "more"...
0
by: dwelch91 | last post by:
I'm having a problem using pexpect with 'sudo' on Ubuntu 6.06 (Dapper). Here's the program: #!/usr/bin/env python import pexpect import sys child = pexpect.spawn("sudo apt-get update")...
5
by: half.italian | last post by:
Hi all. I try not to post until I am stuck in hole with no way out. I fought with this for several hours, and am currently in the hole. I'm doing a proof of concept for creating afp shares...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.