[Stackless] Help using stackless with threads

inhahe inhahe at gmail.com
Sat Jul 19 12:53:56 CEST 2008


On Tue, Jul 15, 2008 at 8:44 AM, Jeff Senn <senn at maya.com> wrote:
>
> 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...)
>

Thanks, it looks like that'll work, assuming there's no spinlock
involved.  but i guess there can't be with the gil?

but i still need to use tasklets with the threads a little bit.   i'm
using stackless anyway (for the main project), and when a tasklet adds
something to the queue, it passes a channel and when after the worker
thread executes the request it sends the result back to that channel.
do the subtle issues you mentioned apply there?

thanx




More information about the Stackless mailing list