[ale] Python (or other) socket identification

Alex Carver agcarver+ale at acarver.net
Sat Feb 4 01:14:31 EST 2017


On 2017-02-03 13:58, Phil Turmel wrote:
> 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.

That's why I was confused because that's where it's already located. :)
It just wasn't working because I couldn't key on socket objects.

> 
>> 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.

I will check this one out, that would make it easier since I don't have
to worry about the destruction process.



More information about the Ale mailing list