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.
Created on 2011年09月14日 13:41 by Florian.Ludwig, last changed 2022年04月11日 14:57 by admin. This issue is now closed.
| Messages (2) | |||
|---|---|---|---|
| msg144024 - (view) | Author: Florian Ludwig (Florian.Ludwig) | Date: 2011年09月14日 13:41 | |
The documentation states: > In non-blocking mode, if a recv() call doesn’t find any data, [...], a error exception is raised; [0] Which is wrong. If no data is available recv() does not raise an exception but returns an empty string. [0] http://docs.python.org/library/socket.html#socket.socket.setblocking |
|||
| msg144216 - (view) | Author: Georg Brandl (georg.brandl) * (Python committer) | Date: 2011年09月17日 18:27 | |
I think you're mistaking a closed connection with "no data available".
Small demo that this works as intended:
>>> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>>> s.connect(('localhost', 1234))
>>> s.recv(10)
^CTraceback (most recent call last):
File "<stdin>", line 1, in <module>
KeyboardInterrupt
>>> s.setblocking(False)
>>> s.recv(10)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
socket.error: [Errno 11] Resource temporarily unavailable
The corresponding server:
>>> x = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>>> x.bind(('', 1234))
>>> x.listen(1)
>>> x.accept()
(<socket._socketobject object at 0x7f4211e997c0>, ('127.0.0.1', 39146))
|
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:57:21 | admin | set | github: 57186 |
| 2011年09月17日 18:27:48 | georg.brandl | set | status: open -> closed nosy: + georg.brandl messages: + msg144216 resolution: works for me |
| 2011年09月14日 13:41:59 | Florian.Ludwig | create | |