My favorites | Sign in
Project Logo
                
Search
for
Updated May 03, 2009 by richard.m.tew
StacklessNetworking  
Stackless networking examples

-- Networking --

Stackless compatible socket module using asyncore

The existing socket module is not usable naturally in a blocking manner with Stackless because of the way that the tasklets share a thread. If a tasklet blocks in the sense that whatever it has done blocks the thread, then this blocks all the tasklets until the operation is complete. Using the standard asyncore module allows asynchronous socket usage, and by adding a minor amount of support code using channels to block calls to it until an error or a result happens, a functionally equivalent socket module replacement can be created.

This replacement module when used allows socket operations which only block the current tasklet, allowing any other tasklets which are scheduled to continue to run while the current tasklet's network operation is handled asynchronously. What was the current tasklet continues running with the result when the operation is complete. If this module is installed in place of the built-in socket module, then all existing code (whether in the standard library or provided by yourself) which uses the built-in version should inherit this behaviour allowing that existing code to be executable in parallel through the use of tasklets.

stacklesssocket.py - Download

Stackless compatible socket module using libevent / pyevent

This module is based on stacklesssocket.py, but replaces asyncore with libevent (via pyevent), aiming for higher performance. Includes basic SSL support.

socketlibevent.py - Download

Simple HTTP Server

An example which adapts the standard library module BaseHTTPServer to handle concurrent requests each on their own tasklet (as opposed to using the ThreadingMixIn from the SocketServer module).

basicWebserver.py - Download

RPC layer

Using the Stackless compatible socket module, it is easy to write a layer that marshals remote procedure calls across a network connection.

stacklessrpc - Browse

MUD server

A simple MUD server written using the Stackless compatible socket module.

mud.py - Download

Chat Server

An example that uses stacklesssocket to provide a chat like application. The users connect via telnet to the IP:port of the server and type in any text and all users connected receives it. The server identifies an special character to close the connection and handle the connected client list.

The example is based on mud.py but uses the standard dispatcher creating a tasklet for each connected client.

chatServer.py - Download


Comment by richard.m.tew, Mar 01, 2008

Deleted a large file which had been pasted in as a comment. If you wish to contribute this, please email the mailing list (at stackless.com).

Comment by richard.m.tew, Mar 10, 2008

Deleted all the comments related to TCP and UDP recv/recvfrom behaviour. I have applied the changes from sgk's comments.

Comment by russandheather, Aug 25, 2008

stacklesssocket.py unit tests failed for me. On investigation it turns out that someone else saw this and already fixed it... this patch worked for me: http://barryp.org/blog/entries/stackless-python-and-sockets/

My (recent) build info... Python 2.5.2 Stackless 3.1b3 060516 (python-2.52:66037, Aug 26 2008, 00:30:07) 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)?


Sign in to add a comment
Hosted by Google Code