[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[ale] Python (or other) socket identification
On 02/03/2017 03:50 PM, Alex Carver wrote:
> device_command_queue = Queue.Queue()
>
> The device daemon thread just checks that queue in each loop to see if
> it's empty or not. If it's not empty, it runs through it and works on
> the data. The data is just tuples: (IP_of_device, payload)
I'm saying put this work into the same thread that select()'s the
sockets for incoming data. That thread has the true and threadsafe
list of sockets.
> Where I'm not following is making the weak reference.
>
> So you're saying something like:
>
> dict[IP] = weakref.ref(socket)
>
> And then if the socket goes away, the IP key is still present but it
> will be pointing at None?
Or just use the WeakValueDictionary class. If the socket closes for any
reason, it will automatically disappear from the dictionary.
Phil