I would like to know if socket.recvfrom in python is a blocking function ? I couldn't find my answer in the documentation If it isn't, what will be return if nothing is receive ? An empty string '' ? In the other case, if in fact, it is blocking, how can i do to put it as an unblocking function ? I heard about settimeout but I don't know if it is actually the right solution.
Asked
Active
Viewed 6,274 times
1 Answers
8
By default it is blocking. It can be turned into non-blocking via socket.setblocking(0)
or (equivalently) socket.settimeout(0)
. In that case if there is nothing to receive it will throw socket.error
exception.
See the docs:

Gabriel Staples
- 36,492
- 15
- 194
- 265

freakish
- 54,167
- 9
- 132
- 169