[Stackless] stackless inter-thread queues

Paul Sijben sijben at eemvalley.com
Tue Mar 17 13:28:13 CET 2009


Hi Andrew,

thanks for this input. The was one little snag, an infinite loop of
stackless.schedule() pust CPU load at 100%. So I now solved it like this:
    def run(self):
    .....
        switchboard=stackless.tasklet(self.switchboard)
        switchboard.setup()
        while self.NotDead:
            if stackless.getruncount()>1:
                stackless.schedule()
            else:
                time.sleep(0.0001)
 
    def switchboard(self):
        while self.NotDead:
            try:
                bla=self.workerQueue.get() 
                (returnQueue,cmdLink,callme,params)=bla
                t=stackless.tasklet(self.runner)
                t.setup(returnQueue,callme,params)
                stackless.schedule()

          ...etc...

where workerqueue.get() ends up being a channel.receive()

My code runs again, until now without deadlocking!

Andrew Francis wrote:
> Hi Paul:
>
>   
>> Message: 7
>> Date: Tue, 17 Mar 2009 09:59:09 +0100
>> From: Paul Sijben <sijben at eemvalley.com>
>> Subject: Re: [Stackless] stackless inter-thread queues
>> To: Richard Tew <richard.m.tew at gmail.com>
>> Cc: stackless at stackless.com
>> Message-ID: <49BF665D.20807 at eemvalley.com>
>> Content-Type: text/plain; charset="iso-8859-1"
>>     
>
>   
>> Hi Richard,
>>     
>
>   
>> Being faced with the situation that I need queue-like behaviour, so one
>> tasklet needs to be waiting on the channel and in some cases this is the
>> only tasklet.
>>     
>
> Paul you should be looking to see why other tasklets don't rendezvous with the waiting tasklet's channel? 
>
>   
>> Is there a way I can make a dummy tasklet to be scheduled when there is
>> noting else to do? But one that does not load the CPU?
>>     
>
> Paul, it has been a while since I played with threads and stackless. I found threads and queues typically hid a design problem. Then again, I haven't used UIs.
>
> I believe to keep the application alive, I did something like:
>
> <your code goes here>
>
> while flag:
>     stackless.schedule()
>
> in the main tasklet. If there is nothing, only the main tasklet gets scheduled. I believe there is an example in the Stackless Google repository.
>
> Again, I would have to look at the code. However when you need queues and dummy tasklets, it sounds like there is a more straightforward solution.
>
> Cheers,
> Andrew
>
>
>       
>   

-- 
Paul Sijben                    	tel: +31334566488
Eemvalley Technology BV       	fax: +31334557523
the Netherlands                	http://eemvalley.com    
-----------------------------------------------------
EemValley Technology werft python & wxpython 
programmeurs: http://www.eemvalley.nl/jobs

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.stackless.com/pipermail/stackless/attachments/20090317/7f75e956/attachment.htm>


More information about the Stackless mailing list