Open pitrou opened 12 years ago
This decrepancy between 2.x and 3.x is witnessed under Windows:
Python 2.7.1 (r271:86832, Nov 27 2010, 17:19:03) [MSC v.1500 64 bit (AMD64)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import socket
>>> sock = socket.create_connection(("www.python.org", 80))
>>> sock.close()
>>> sock.send(b"x")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "c:\python27\lib\socket.py", line 170, in _dummy
raise error(EBADF, 'Bad file descriptor')
socket.error: [Errno 9] Bad file descriptor
Python 3.2.1 (default, Jul 10 2011, 20:02:51) [MSC v.1500 64 bit (AMD64)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> import socket
>>> sock = socket.socket(); sock.connect(("www.python.org", 80))
>>> sock.close()
>>> sock.send(b"x")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
socket.error: [Errno 10038] An operation was attempted on something that is not
a socket
I'm not sure this is worth fixing, though.
discrepancy, not decrepancy :S
(10038 is WSAENOTSOCK, by the way)
According to strace, Python 3 is calling send(-1, ...):
sendto(-1, "x", 1, 0, NULL, 0) = -1 EBADF (Bad file descriptor)
A related discrepancy between Python 2 and 3 is how the socket.makefile() objects affect the original socket. In Python 2:
>>> f = sock.makefile("wb")
>>> sock.close() # Should “close” Python’s sock object, but not f
>>> sock.send(b"x")
socket.error: [Errno 9] Bad file descriptor
In Python 3:
>>> sock.send(b"x") # Actually sent to remote end!
1
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields: ```python assignee = None closed_at = None created_at =
labels = ['type-bug', 'library']
title = "closed sockets don't raise EBADF anymore"
updated_at =
user = 'https://github.com/pitrou'
```
bugs.python.org fields:
```python
activity =
actor = 'martin.panter'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Library (Lib)']
creation =
creator = 'pitrou'
dependencies = []
files = []
hgrepos = []
issue_num = 13344
keywords = []
message_count = 3.0
messages = ['147039', '147041', '269148']
nosy_count = 6.0
nosy_names = ['exarkun', 'pitrou', 'giampaolo.rodola', 'martin.panter', 'colinmarc', 'pconnell']
pr_nums = []
priority = 'low'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue13344'
versions = ['Python 3.2', 'Python 3.3']
```