<html>
<head>
</head>
<body>
One of the biggest pains of doing work with http is<br>
trying to keep track of what's going on in a complex<br>
multistage transaction, when http itself is "stateless".<br>
<br>
This generally results in lots of hidden variables and<br>
the usual state-machine code obfuscation.<br>
<br>
Just wanted to share that I'm having some success<br>
keeping track of "sessions" using tasklets that get "reconnected"<br>
to http interactions within an http server. My first test<br>
for managing sessions within the framework looks like this<br>
at present..<br>
<br>
<br>
def testprocessor(session, channel, scheduler):<br>
donesignal = None<br>
try:<br>
# generate fibonnaci numbers<br>
a = b = 1<br>
memo = "guest"<br>
for i in range(6):<br>
# finish last interaction<br>
if donesignal is not None:<br>
donesignal.send(1)<br>
# wait for next connection for this session<br>
(dictionary, socket, Sock, addr, donesignal, debug) = channel.receive()
<br>
scheduler.send(socket, "HTTP/1.0 200 OK\r\n")<br>
scheduler.send(socket, "Content-type: text/html\r\n")<br>
scheduler.send(socket, "\r\n")<br>
scheduler.send(socket, """<br>
Welcome %s to session %s<hr><br>
i=%s a=%s b=%s<br><br>
<a href="test.cgi?session=%s">go around again!</a><br>
""" % (memo, session, i, a, b, session,))<br>
a, b = b, a+b<br>
memo = "back"<br>
scheduler.send(socket, "<h3>This session is done now</h3>")<br>
donesignal.send(1)<br>
finally:<br>
if donesignal is not None and donesignal.balance<0: # ???<br>
donesignal.send(1)<br>
<br>
In the session tasklet this function generates 6 screens in sequence when
the user presses<br>
"go around again". The first looks like this:<br>
<br>
Welcome guest to session 1031330478.68
<hr> i=0 a=1 b=1<br>
<a href="http://localhost:8000/test.cgi?session=1031330368.23">go around
again!</a>
<br>
<br>
and the last looks like this<br>
<br>
Welcome back to session 1031330478.68
<hr> i=5 a=8 b=13<br>
<a href="http://localhost:8000/test.cgi?session=1031330478.68">go around
again!</a>
<h3>This session is done now</h3>
The interesting thing is that this is "straight line code" even though<br>
the 6 http interactions are independent.<br>
<br>
Having implemented more HTTP state machines than a sane person should<br>
be permitted on one lifetime I'm finding this alternative quite refreshing
:).<br>
Comments?<br>
<br>
I'll share some code once I've played a bit more.<br>
<br>
-- Aaron Watters<br>
<br>
<br>
</body>
</html>