Friday, February 23, 2007

Asynchronous Sockets

I've looking at the pdis source directory and found an interesting module: async_socket.py

I think this might resolve our GPS thread issues as you can now perform a read in the background:

Here the python docstring:

class AsyncSocket:
"""
Defines an asynchronous socket interface. Implementors are not
required to inherit this class, but they must define the same
interface.

Note that only the thread that creates an instance of this class
may access the instance.

Note also that all the callbacks made by this object are
passed the following parameters, in the order listed:

1. event originator (an ``AsyncSocket`` handle)

2. event type (the name of the method used to make the request)

3. status (an ``Exception`` instance, or ``None`` if no error)

4. any request-specific payload (or ``None`` if none)

5. callback parameter, as specified when making the request
"""

And this is the docstring of the recieve command:

def recv(self, size, cb_func, cb_param):
"""
Makes a request to read at most ``size`` bytes from the
socket, and to call the ``cb_func`` callback function passing
the result as well as ``cb_param`` as function arguments.

The callback will not be made until the operation either
completes or fails. An empty string is returned as the
requested data to signal an EOF sent by the peer.

At most one ``recv`` request at a time may be outstanding.
"""
raise NotImplementedError

No comments: