When using socket.socket.s ettimeout we normally only guard against
"socket.timeout " exception.Now the implementation of "settimeout " in
"Python-2.4.3/Modules/socketmodule.c" sets the socket fd to
nonblocking and uses "select()" to timeout
as seen below in line 1487 and 1386 :
static PyObject *
1470 sock_settimeout (PySocketSockOb ject *s, PyObject *arg)
1471 {
1472 double timeout;
............... ...............
1485
1486 s->sock_timeout = timeout;
1487 internal_setblo cking(s, timeout < 0.0);
1488
1489 Py_INCREF(Py_No ne);
1490 return Py_None;
1491 }
1492
1362 sock_accept(PyS ocketSockObject *s)
1363 {
...
1385 Py_BEGIN_ALLOW_ THREADS
1386 timeout = internal_select (s, 0);
1387 if (!timeout)
1388 newfd = accept(s->sock_fd, (struct sockaddr *)&addrbuf,
1389 &addrlen);
1390 Py_END_ALLOW_TH READS
1391
Now internal_select () returns "1" on timemout else "0" as seen below
:
673 n = select(s->sock_fd+1, &fds, NULL, NULL,&tv);
674 if (n == 0)
675 return 1;
676 return 0;
back to the sock_accept() fuction on line 1387
1387 if (!timeout)
1388 newfd = accept(s->sock_fd, (struct sockaddr *) &addrbuf,
1389 &addrlen)
if "select()" returned before timeout we call "accept()"
Now my observation on FC4 ( kernel version 2.6.11-1.1369_FC4)
"select()" can return before timeout with a
"Interrupte d system call" (EINTR) error,
my question is , is it possible that our internal_select () fuction as
seen on line 676 above returns "0" and we go on to do a "accept()" call
which returns with a "Resource temporarily unavailable" error if the
sockfd is not readable. So user expects only "socket.timeout " but gets
"Resource temporarily unavailable" which stops the program
from proceeding.
Our Case : We are using CherryPy , which sets a timeout on socket using
"settimeout " and whenever our code uses "os.seteuid " cherrpy dies
giving
out the "Resource temporarily unavailable".
I did write a "C" program using pthreads , one thread doing
non blocking accept() and select() and other thread doing a seteuid()
..
select() did bail out giving Interrupted system call Error.
Thanks
Jitendra Nair 1 4458
In article <11************ **********@i40g 2000cwc.googleg roups.com>, jn***@ensim.com wrote: Now my observation on FC4 ( kernel version 2.6.11-1.1369_FC4) "select()" can return before timeout with a "Interrupte d system call" (EINTR) error,
Nothing Red-Hat-specific, or even Linux-specific, about this. It's a
standard *nix thing. _All_ potentially time-consuming system calls (such
as select(2), read(2), write(2)) can return EINTR, or some other
indication that they didn't do everything they were asked to do.
<http://en.wikipedia.or g/wiki/PCLSRing>
my question is , is it possible that our internal_select () fuction as seen on line 676 above returns "0" and we go on to do a "accept()" call which returns with a "Resource temporarily unavailable" error if the sockfd is not readable.
The semantics of select(2) is that you're supposed to check the
returrned bitmasks and only take the appropriate actions if the
corresponding read-ready, write-ready and error bits are set.
See the select(2) man page for more on this. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Nagy László Zsolt |
last post by:
Hi Python Gurus!
Here is a method I used before to receive data over a socket (with
Python 2.2):
SELECT_GRANULARITY = 0.1 # 0.1 seconds
def readdata(self,length,timeout):
res = ''
remain = length
|
by: Nagy László Zsolt |
last post by:
Hi Python Gurus!
Here is a method I used before to receive data over a socket (with
Python 2.2):
SELECT_GRANULARITY = 0.1 # 0.1 seconds
def readdata(self,length,timeout):
res = ''
remain = length
|
by: Colin Brown |
last post by:
I have set up a socket listener that needs to listen indefinitely. On an
incoming call I get a connection object that I want to set a timeout on
. As the setdefaulttimeout method did not work with the new
connection I found (using dir on the socket._socket object) a settimeout
method. Is this (undocumented) method peculiar to Windows or fully
cross-platform?
code fragment:
conn = rcv.nextConnAddr()
print conn
|
by: Thomas Hervé |
last post by:
My problem is not really python specific but as I do my implementation
in python I hope someone here can help me.
I have two programs that talk through a socket. Here is the code :
<server>
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.settimeout(5.0)
|
by: flupke |
last post by:
Hi,
I have a gui (made in wxPython) that enables a user to connect to a server
and issue some commands. The problem occurs when i try to disconnect the
client. It exits but it doesn't return to the prompt. I have to push
Ctrl-C in order to have it exit completely. The GUI is closed though.
This is a piece of code from the main class that connects to the server
and starts a thread that handles the connection:
=======================...
| |
by: PantherSE |
last post by:
Hello,
Ok, here's my situation. I have a small application that listens to
messages on a UDP port.
When I pass None to settimeout(), and I hit Ctrl+C to interrupt the
wait my exception handler catches the KeyboardInterrupt exception.
However, if I pass any value to settimeout() the exception is not
caught.
|
by: domeceo |
last post by:
can anyone tell me why I cannot pass values in a setTimeout function
whenever I use this function it says "menu is undefined" after th
alert.
function imgOff(menu, num) {
if (document.images) {
document.images.src = eval("mt" +menu+ ".src")
}
alert("imgOff_hidemenu");
hideMenu=setTimeout('Hide(menu,num)',500);
|
by: ahlongxp |
last post by:
Hi, everyone,
I'm implementing a simple client/server protocol.
Now I've got a situation:
client will send server command,header paires and optionally body.
server checks headers and decides whether to accept(read) the body.
if server decided to throw(dump) the request's body, it'll send back a
response message, such as "resource already exists" and close the
connection.
|
by: Hendrik van Rooyen |
last post by:
While doing a netstring implementation I noticed that if you
build a record up using socket's recv(1), then when you close
the remote end down, the recv(1) hangs, despite having a short
time out of 0.1 set.
If however, you try to receive more than one char, (I tested with 3,
did not try 2), then when you shut the remote end down you do not
get a time out, but an empty string - the normal end of file, I suppose.
Has anybody else seen...
|
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...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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...
|
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,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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
| |