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

timeout on on socket using alarm signal??

System Mandrake-9.1 Linux with Python-2.2.3

Tyring to time out from a non respnding server using SOCK_STREAM

Source is shown below

The program quits after first receipt of alram signal with messge

socket.error(4, 'Interrupted system call')

is there a way to retry the send and receive process?

-ishwar
----
import signal, sys
from socket import *
aTry = 0

def onalarm(signum, stackframe):
global aTry
if signum == signal.SIGALRM:
aTry = aTry + 1
print 'Alram seen..', aTry

signal.signal(signal.SIGALRM, onalarm)

def main():
global aTry
serverHost = 'localhost'
serverPort = 6007
mesg = 'hello there'

sockobj = socket(AF_INET, SOCK_STREAM)
sockobj.connect((serverHost, serverPort))

while aTry < 5:
sockobj.send(mesg)
signal.alarm(1)
data = sockobj.recv(1024)
if data:
print 'Got: ', data
sockobj.close()
break
else:
aTry = aTry + 1
print 'No reply from server..'
sockobj.close()

if __name__ == '__main__':
main()
----
Jul 18 '05 #1
0 1261

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

Similar topics

3
by: w | last post by:
I'm having problems with this program hanging on the revc(buf). I was trying to figure out a way to allow the socket to timeout. I'm have tried making the socket non-blocking but had on luck. ...
2
by: Oliver Kurz | last post by:
Hello, do someone new how I can do the following? I call a method which reads from a socket. So ... this method could hang forever and so my call hangs too ... So ... I can not change the...
5
by: Jim | last post by:
Hi, I am trying to figure out a way to implement a timeout along with a read() call on an open file. It only has to work on linux, for now I am trying: ret = select.select( ,,, timeout ) if...
0
by: Ishwar Rattan | last post by:
System is Mandrale 9.1 Linux with Pyhton-2.2.3 I want to abort the stdin-read operation if no input is avalable. Is it possible to achieve this? Sample code is given below. -ishwar ---...
0
by: rh0dium | last post by:
Hi all, I don't understand the signal module. I guess I understand what it does in principle but I can't figure out how to use it to timeout an external rsh command after a 5 seconds. Does...
8
by: Thierry Lam | last post by:
I can use the python function raw_input() to read any input from the user but how can I add a timeout so that my program exits after x period of time when no input has been entered. Thierry
11
by: Stefan Palme | last post by:
Hi all, is there a way to modify the time a call of urllib.open(...) waits for an answer from the other side? Have a tool which automatically checks a list of websites for certain content....
0
by: Carles Pina i Estany | last post by:
Hello, I need to implement timeout for execute method in Mysql queries. I am using MySQLdb. I have tried it: signal.signal(signal.SIGALRM,handler) signal.alarm(1) cursor.execute(sql)...
12
by: Sophie000 | last post by:
I am implementing a peer-to-peer program: When a computer A receives “get file XXX” from stdio, it broadcasts (floods) a request packet to ask others. Both Computer B and C have the file so they...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.