Thread safety of UDP sendto
jeff at ccvcorp.com
Thu Jun 21 18:57:54 EDT 2001
"Jeffrey W. Collyer" wrote:
> An odd question perhaps, but is Python's UDP socket.sendto() thread safe?
> I have a multi-threaded app that I would like to send off some UDP packets.
> The data for the packets is gathered in each thread. If I get a socket
> handle in each thread it will be less efficient than if I open one upon
> program start and then have each thread just do an
> ubersocket.sendto(data,ADDR). Or am I missing something more basic?
> What I really need is an atomic write function that handles threading, but
> I'll settle for a cheap UDP solution.
My initial thought would be to designate one thread to handle the socket, and
have all of the other threads forward their data to the socket thread via some
sort of queue. Variations in the queue could allow you to organize the data
in whatever way was appropriate for your particular circumstance.
More information about the Python-list