Author neologix
Recipients christian.heimes, felipecruz, giampaolo.rodola, gvanrossum, neologix, pitrou, rosslagerwall
Date 2013-01-05.20:23:27
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <CAH_1eM03Pd81CSkw_6-vqEbGpmFB7KFbAWVQzuFCm8Fd4QBbOA@mail.gmail.com>
In-reply-to <1357413623.62.0.533965253733.issue16853@psf.upfronthosting.co.za>
Content
> I think that this needs extensive tests that verify the behavior of many end cases, including under duress (e.g. when there are too many connections for the kernel to handle).  That would seem the only way to make sure that the code is reliable across platforms.  It is likely that you could borrow some ideas for test scenarios from Twisted.

Will do.

I'm adding a new version taking into account some of Giampaolo's remarks.

Also, the API now also allows passing a file descriptor or any object
with a `fileno()` method, since it will likely be useful.

To sum up, the API is:

    def register(self, fileobj, events, data=None):
        """Register a file object.

        Parameters:
        fileobj -- file object
        events  -- events to monitor (bitwise mask of SELECT_IN|SELECT_OUT)
        data    -- attached data
        """

    def unregister(self, fileobj):
        """Unregister a file object.

        Parameters:
        fileobj -- file object
        """

    def modify(self, fileobj, events, data=None):
        """Change a registered file object monitored events or attached data.

        Parameters:
        fileobj -- file object
        events  -- events to monitor (bitwise mask of SELECT_IN|SELECT_OUT)
        data    -- attached data
        """

    def select(self, timeout=None):
        """Perform the actual selection, until some monitored file objects are
        ready or a timeout expires.

        Parameters:
        timeout -- if timeout > 0, this specifies the maximum wait time, in
                   seconds
                   if timeout == 0, the select() call won't block, and will
                   report the currently ready file objects
                   if timeout is None, select() will block until a monitored
                   file object becomes ready

        Returns:
        list of (fileobj, events, attached data) for ready file objects
        `events` is a bitwise mask of SELECT_IN|SELECT_OUT

Selector.select() output looks a lot like poll()/epoll() except for
two details: the output is the file object, and not the file
descriptor (poll()/epoll() are unfortunately inconsistent in this
regard), and there's a third field, the attached data (will be None if
not provided in register()/modify()). I think that this optional field
is really useful to pass e.g. a callback or some context information.
Files
File name Uploaded
selector-5.diff neologix, 2013-01-05.20:23:26
History
Date User Action Args
2013-01-05 20:23:27neologixsetrecipients: + neologix, gvanrossum, pitrou, giampaolo.rodola, christian.heimes, rosslagerwall, felipecruz
2013-01-05 20:23:27neologixlinkissue16853 messages
2013-01-05 20:23:27neologixcreate