Issue 30204: socket.setblocking(0) changes socket.type

Issue30204

Created on 2017-04-29 08:23 by giampaolo.rodola, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (3)
msg292576 - (view) Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) Date: 2017-04-29 08:23
This caused me a lot of headaches (broken test) before figuring out what the heck was wrong: =)

>>> import socket
>>> s = socket.socket()
>>> s.type
<SocketKind.SOCK_STREAM: 1>
>>> s.setblocking(0)
>>> s.type
2049
>>> s.setblocking(1) 
>>> s.type
<SocketKind.SOCK_STREAM: 1>


getsockopt() on the other hand always tells the truth:

>>> s.getsockopt(socket.SOL_SOCKET, socket.SO_TYPE)
1


...so I suppose we can do that in the "type" property of the Python socket class.
It appears the type is set in socket init:
https://github.com/python/cpython/blob/1e2147b9d75a64df370a9393c2b5b9d170dc0afd/Modules/socketmodule.c#L904
...and it's changed later in setblocking:
https://github.com/python/cpython/blob/1e2147b9d75a64df370a9393c2b5b9d170dc0afd/Modules/socketmodule.c#L609
msg292587 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2017-04-29 09:26
Is this a duplicate of Issue 21327? There is some discussion there and a patch to add get_socket_type that excludes SOCK_NONBLOCK.
msg292588 - (view) Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) Date: 2017-04-29 09:31
Woo! I completely forgot I already bumped into this and that I even filed a ticket for it.
History
Date User Action Args
2022-04-11 14:58:45adminsetgithub: 74390
2017-04-29 09:31:34giampaolo.rodolasetstatus: open -> closed
resolution: duplicate
messages: + msg292588

stage: resolved

2017-04-29 09:26:53martin.pantersetsuperseder: socket.type value changes after using settimeout()

messages: + msg292587
nosy: + martin.panter

2017-04-29 08:23:43giampaolo.rodolacreate