mirror of
https://github.com/micropython/micropython.git
synced 2026-01-04 11:10:14 +01:00
After s.close(), s.fileno() now returns -1, matching CPython behavior. Some code relies on this compatibility, as it allows checking whether a socket is closed by testing its fileno() value. This change ensures better interoperability with existing Python code and libraries. Signed-off-by: Mike Wang <mikewang000000@gmail.com>
18 lines
294 B
Python
18 lines
294 B
Python
# Test socket.fileno() functionality
|
|
|
|
try:
|
|
import socket
|
|
except ImportError:
|
|
print("SKIP")
|
|
raise SystemExit
|
|
|
|
if not hasattr(socket.socket, "fileno"):
|
|
print("SKIP")
|
|
raise SystemExit
|
|
|
|
s = socket.socket()
|
|
print(s.fileno() >= 0)
|
|
|
|
s.close()
|
|
print(s.fileno()) # should print -1
|