[Stackless] Stackless and Twisted [was: Stackless and Psyco]

Christopher Armstrong radix at twistedmatrix.com
Mon Mar 1 21:32:19 CET 2004


Bob Ippolito wrote:
> Next time I do a bunch of socket code, I'm 
> going to do it in stackless..  I've already started on a barebones 
> networking framework that will hopefully interoperate with existing 
> twisted, blocking-style, and medusa/asyncore style code.

Here's a word of warning: I've done some work on a stackless 'reactor' 
for Twisted (probably actually doing a reactor is a bad way to do it). 
After some discussion with James Knight on the subject, I realized that 
it can't be compatible with all current framework code. e.g.:

def currentFrameworkCode():
  contextlist.append(1)
  blockingUserCode()
  contextlist.append(2)

If blockingUserCode does a context-switch, then currentFrameworkCode's 
assumptions are broken (that it would have a list like [..., 1, 2, 
...]). However, you could write something similar to deferToThread for 
stackless, and then it would work out fine *for framework code that 
expects Deferreds*, AFAICT (I just realized this today, actually):

userCode = deferToStacklessWrapper(userCode)

def currentFrameworkCode():
   contextlist.append(1)
   return userCode().addCallback(lambda r: contextlist.append(2))

Of course the author of currentFrameworkCode here would understand that 
he might not always get [..., 1, 2, ...], since he's expecting a 
Deferred... maybe this isn't a great example. :-) Tell me if you need 
clarification.

Anyway, fortunately Deferreds are so ubiquitous that you'll probably be 
fine in most cases you want to context switch, but you'll still have to 
watch out for the prior case.

I actually stopped working on my stackless integration because I was 
afraid of breaking framework-code's assumptions, but I just realized 
that it would be fine for Deferredy framework-code today. Maybe I'll 
start hacking on it again... or maybe I'll just let you do it ;-)

Good luck,

-- 
  Twisted | Christopher Armstrong: International Man of Twistery
   Radix  |          Release Manager,  Twisted Project
---------+           http://radix.twistedmatrix.com/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 256 bytes
Desc: OpenPGP digital signature
URL: <http://www.stackless.com/pipermail/stackless/attachments/20040301/0d37da43/attachment.pgp>
-------------- next part --------------
_______________________________________________
Stackless mailing list
Stackless at stackless.com
http://www.stackless.com/mailman/listinfo/stackless


More information about the Stackless mailing list