[Stackless] Problems with Queues in Microthread Lib.

Will Ware wware at world.std.com
Fri Mar 16 16:27:38 CET 2001


Queues have the behavior of blocking when they are not given
input. Your queues are indeed blocking because you have never
used their put() method to give them input. So you are wondering
why they quit, and don't just stay blocked.

The reasoning here is that if all your microthreads are blocked,
then there is no way for any of them ever to become unblocked.
So the engine that runs the microthreads, if it ever determines
that all the microthreads are blocked simultaneously, quits them
all and returns from the uthread.run() call.

The assumption that they could never unblock may be unwarranted.
They could perhaps block on a signal from outside the microthread
environment. As far as I can see, that would need to come from
another OS thread, or perhaps some I/O event like waiting for an
HTTP response (which probably amounts to another OS thread). Maybe
uthread.run() should instead throw an exception, leaving the
microthreads in a state that is easily continuable if it's deemed
that the exception should be ignored. Something like this:

    while 1:
        try: uthread.run()
        except AllUthreadsAreBlocked:
            if not otherOSthreadIsBehavingCorrectly:
                break
            # else just keep doing uthread.run(), waiting for
            # some magical event from elsewhere

In your case, the "correct" behavior would have been to print the
first two lines "Somehow I get here", and then just sit there
forever. Correct but inconvenient, hence the behavior you see.

The reason the cget() method is returning None is that it is a
non-blocking version of the get() method. It's supposed to return
something quickly, whether the queue is empty or not. It seemed
reasonable to return None if the queue was empty.

Thinking about it a second time, it makes more sense to me that
cget() should throw an exception. This would still give a fast
response but None would not be a magic value. It would allow people
to put None's in their queues without ambiguity. And throwing an
exception just seems the correctly Pythonic thing to do.

-----Original Message-----
From: stackless-admin at starship.python.net
[mailto:stackless-admin at starship.python.net]On Behalf Of James Turner
Sent: Friday, March 16, 2001 10:25 AM
To: stackless at starship.python.net
Subject: [Stackless] Problems with Queues in Microthread Lib.

--- start code ---
import uthread
THREAD_NUM = 2
def worker_function(mqueue):
        print "Somehow I get here..."
        mqueue.get()
        print "But not here..."
request_queue = uthread.Queue()
for i in range(0,THREAD_NUM):
    uthread.new(worker_function,request_queue)
uthread.run()
--- end code ---
bash# python test.py 
Somehow I get here...
Somehow I get here...
bash#  
Ack!  I thought at first that get() was just not 
blocking for me, but now it appears that it\'s quitting
the microthread entirely for some reason!  

_______________________________________________
Stackless mailing list
Stackless at starship.python.net
http://starship.python.net/mailman/listinfo/stackless



More information about the Stackless mailing list