[Stackless] Fwd: Multi-Threaded Stackless Example

Richard Tew richard.m.tew at gmail.com
Sat Apr 14 10:45:44 CEST 2007

Hi everyone,

Benjamin kindly submitted this new example, which he goes into lots of
detail about below.  Unfortunately I got overwhelmed by a lot of stuff
and let it sit in my mailbox forgetting about it.  I have now checked
it into the SVN examples repository here:


Benjamin: If you want to submit another extended example which depends
on STL-Plus, please do.  I think it would go nicely with this example
and would definitely be another good addition to the examples.

Thanks and sorry for the delay,

---------- Forwarded message ----------
From: Benjamin Tolputt <bjt at pmp.com.au>
Date: Apr 2, 2007 5:26 AM
Subject: Multi-Threaded Stackless Example
To: Richard Tew <richard.m.tew at gmail.com>

G'day Richard,

I have finished (as promised) the example of using Stackless in a
multi-threaded environment where the main thread is dedicated to the
Stackless processing and any secondary threads are used to execute
native (i.e. no Python what-so-ever) code. It also has embeds a test
framework for having two types of sleeping tasklet - the first type
being "real-time" sleeping woken up after X milliseconds of real-time,
and the other being woken up after X time units of "world time" (useful
for games & simulations). However, the code is commented clearly enough
(I hope) to easily differentiate between the two tests.

I utilised Boost for the network & "noise"/random code so as to minimize
the code's dependencies on external libraries. I use STL-Plus for TCP/IP
communication, but did not want to burden the user with more libraries
to download/install. As such, there is no "real" network communication,
but the threading is real and works nicely.

I should note, that while the application is based on ideas from the
embedDemo in SVN - I rewrote this set of code from scratch. I work
commercially and find examples & frameworks that apply more than a
contribution & warranty disclaimer to be a pain. Especially when it is
being presented as an example in an otherwise "nice" package. which is
not to say it shouldn't be done (each developer has every right to
license their code as they or their company desires). I simply like the
idea that my code might be the first steps to "implementing" something
cool, not just the code read to "learn" about something cool.

I'm releasing this under a BSD/MIT license (all I care about is the fact
that people know where the code came from, that's it). I was hoping you
could put it up in the Wiki and/or mention it on the list if it passes
muster with you. I develop on Windows in MSVC, hence the project files
and no Linux makefile. Hopefully though it should be easy to link as all
I used was Boost.Python, Boost.Thread, & Boost.Random - the last of
which does not need to link to any library files. I have also only
tested on Python 2.5 but, given the stacklesssocket example, I didn't
think this would be an issue.

Any questions - feel free to bug me. If it helps to understand the code,
I'll even answer the question in the code comments and resend/reupload.
If you have a question on something - it is likely that others will too.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: thread_server.zip
Type: application/zip
Size: 11710 bytes
Desc: not available
URL: <http://www.stackless.com/pipermail/stackless/attachments/20070414/c219148e/attachment.zip>
-------------- next part --------------
Stackless mailing list
Stackless at stackless.com

More information about the Stackless mailing list