[PEAK] events.io_events.Selector question

Phillip J. Eby pje at telecommunity.com
Wed Jul 4 21:22:42 EDT 2007

At 04:15 PM 7/4/2007 +0300, ilja wrote:
>I can't get trough one type of error working with sockets and PEAK 
>'Selector' class.
>I have a socket that is being monitored (using Selector) for 
>'readable' and 'writable' state.
>Event source is being obtained using binding.Make.
>readable_evt = binding.Make(lambda self: self.selector.readable(self.socket))
>writable_evt = binding.Make(lambda self: self.selector.writable(self.socket))
>After each event firing I subscribe object's callback to for this 
>event using 'addCallback' method. The cancelers for last subscribed 
>callbacks are being stored.
>So, when i need to close socket, I first call canceler methods, and 
>then socket.close() method.
>It just happens that sometimes my socket objects (after cancelers 
>are called and sockets are closed) are not being deleted from 
>'Selector' socket cache. So, during next Selector's 'monitor' method 
>iteration I get error """(10038, 'An operation was attempted on 
>something that is not a socket')""" (It is being raised because my 
>closed socket is being given to select() function).
>Because of this error PEAK reactor falls apart and application terminates.
>Basically, I would like to know what I'm doing wrong and how to fix it. :)

I think it's not you, it's me.  :)  It looks like AbstractIOEvent 
doesn't update its activation when callbacks are cancelled.  Try the 
patch below for now and let me know if it fixes your problem.  If so, 
I will add a test and get it into SVN for you.

Index: src/peak/events/io_events.py
--- src/peak/events/io_events.py        (revision 2125)
+++ src/peak/events/io_events.py        (working copy)
@@ -69,7 +69,8 @@

      def addCallback(self,func):
-            return super(AbstractIOEvent,self).addCallback(func)
+            canceller = super(AbstractIOEvent,self).addCallback(func)
+            return lambda: (canceller(), self._register())

More information about the PEAK mailing list