Socket python: recvfrom

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 doesn't, what if it doesn't get anything? Empty line ''? Otherwise, if in fact it blocks, how can I do it as an unlock function? I've heard about settimeout , but I don't know if this is really the right solution.

Thank. Xavier

+3


source to share


1 answer


It is blocked by default. It can be made non-blocking via socket.setblocking(0)

or (equivalently) socket.settimeout(0)

. In this case, if nothing is received, it will throw an exception socket.error

. See docs: https://docs.python.org/2/library/socket.html#socket.socket.setblocking



+4


source







All Articles