homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author piotrjurkiewicz
Recipients piotrjurkiewicz
Date 2015年01月30日.01:28:09
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1422581292.34.0.901742947923.issue23351@psf.upfronthosting.co.za>
In-reply-to
Content
After setting socket.settimeout(5.0), socket.send() returns immediately, instead of returning after specified timeout.
Steps to reproduce:
Open two python interpreters.
In the first one (the receiver) execute:
>>> import socket
>>> r = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
>>> r.bind("test.sock")
In the second one (the sender) execute:
>>> import socket
>>> s = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
Then run the following command 11 times:
>>> s.sendto("msg", "test.sock")
On the 12 run command will block. This happens because datagram sockets queue on Linux is 11 messages long. Interrupt the command.
So far so good.
Then set sender socket timeout:
>>> s.settimeout(5.0)
Expected behavior:
s.sendto() should block for a 5 seconds and THEN raise error 11 (EAGAIN/EWOULDBLOCK).
Actual behavior:
s.sendto() raises the error IMMEDIATELY.
>>> s.sendto("msg", "test.sock")
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
socket.error: [Errno 11] Resource temporarily unavailable
So, in fact, s.settimeout(5.0) does not have any effect.
I think that problem is that settimeout() sets the socket to the non-blocking mode (docs say: "Timeout mode internally sets the socket in non-blocking mode.").
As described [here](http://stackoverflow.com/q/13556972/2178047) setting timeout on non-blocking sockets is impossible.
In fact, when I set timeout manually with setsockopt(), everything works as expected:
>>> s.setblocking(1) #go back to blocking mode
>>> tv = struct.pack("ll", 5, 0)
>>> s.setsockopt(socket.SOL_SOCKET, socket.SO_SNDTIMEO, tv)
Now s.sendto() raises the error after 5 seconds, as expected.
History
Date User Action Args
2015年01月30日 01:28:12piotrjurkiewiczsetrecipients: + piotrjurkiewicz
2015年01月30日 01:28:12piotrjurkiewiczsetmessageid: <1422581292.34.0.901742947923.issue23351@psf.upfronthosting.co.za>
2015年01月30日 01:28:12piotrjurkiewiczlinkissue23351 messages
2015年01月30日 01:28:09piotrjurkiewiczcreate

AltStyle によって変換されたページ (->オリジナル) /