[Stackless] Help using stackless with threads

Jeff Senn senn at maya.com
Tue Jul 15 14:44:17 CEST 2008

On Jul 15, 2008, at 4:41 AM, inhahe wrote:

> Can someone help me with using stackless with python threads.  I'm
> trying to make a thread pool for database access using stackless
> channels to activate the threads because I can't use signals because
> I'm on Windows.  So I run 4 threads (using the thread module) and each
> thread runs 1 stackless tasklet in an infinite loop that waits to
> receive from a unique channel.  But it seems all four of them fall
> through the receive() call each iteration - whether I send something
> or not - and I'm guessing it's because each one thinks that it's the
> last tasklet running because it's the only tasklet in its thread.  So
> how do I fix this?  Here's the code I have..

Hi inhahe-

Are you sure you really want/need stackless?   It sounds like,
for your purpose, using the (regular python) Queue class
(with the thread-compatible .get()/.put() methods)
is what you need.

Stackless was not originally designed to schedule between
threads -- nor to put a thread to "sleep"... (there are
some subtle issues there that have been discussed on this
list several times before...)

More information about the Stackless mailing list