[Stackless] porting from python-multitask to stackless

Ghulam Mustafa mustafa.pk at gmail.com
Thu Apr 15 15:56:34 CEST 2010


Hi,

i am going to port a piece of code from python-multitask to stackless,
since i am new to python can someone help me understand how can i port
following simple example to stackless python.

####
def listener(sock):
    while True:
        conn, address = (yield multitask.accept(sock))
        multitask.add(client_handler(conn))

def client_handler(sock):
    while True:
        request = (yield multitask.recv(sock, 1024))
        if not request:
            break
        response = handle_request(request)
        yield multitask.send(sock, response)

multitask.add(listener(sock))
multitask.run()
####

here are my understandings so far.

1. stackless.tasklet is equivalent of multitask.add
2. stackless.run is equivalent of multitask.run

i am not able to understand what is the equivalent of following lines.

        request = (yield multitask.recv(sock, 1024))
        if not request:
            break
        response = handle_request(request)
        yield multitask.send(sock, response)


yield causes a pause so i guess it could be replaced with stackless,
but problem is how do i handle return values :(.

sorry for my little knowledge.

thanks and best regards.

-mustafa



More information about the Stackless mailing list