I was wondering if there is really a need to use for example threading.Lock
when working with Pythons sockets where each thread only sends and receives from that socket. Opening and closing is always handled by the parent.
When searching for an answer most people simply say that sockets are not thread safe and one needs to use something to serialize them. But nobody really explains as to why this is required.
Others say that send
and recv
are thread safe on a operating system level and thus may be used parallel without serialization (here). I don't know if I am correct here but I thought that Python uses the C implementation of POSIX sockets, correct? (What about the Windows implementation of sockets?)
If it not correct that send
and recv
are called without locks then why is that exactly? May it be possible that on thread receives the data that was requested by another?