[Stackless] Q2: Uthread's 'Thread' class

Just van Rossum just at letterror.com
Thu Apr 12 10:19:12 CEST 2001


Ixokai wrote:

> From the microthread documentation: "When threads are created using the
> Thread class, the first argument of the thread's function will be the thread
> instance"

I'm not sure, but it looks like the doco on
http://world.std.com/~wware/uthread.html is still based on the original uthread
module. The above certainly doesn't apply to the current version...

> It gives sample code which basically is basically:
> 
> mythreads = []
> def foo(instance, num):
>     uninteresting_math = num * 2
>     printw('<' + repr(instance) + ' ' + repr(num) + '>')
> 
> for n in range(100):
>     t = uthread.Thread(foo, int(30 * uthread.random()))
>     mythreads.append(t)
> uthread.run()
> 
> etc. Now. I really don't see what's going on :) Looking into uthread.py's
> source tells me that Thread's init method takes at least two arguments; a
> function to call, a 'name' (???), and any args/kwargs you're going to pass
> the function.

Yeah, this means the above code is incorrect ;-)

> It appears as if you are not susposed to sub-class Thread, but instead just
> instantiate a Thread class and pass it a function you wish it to call, and
> any arguments you wish it to pass, in addition to the thread's own instance.
> Am I reading that correctly?

You may subclass the Thread class.

> Now the wall that I am hitting: we are passing in two arguments in the
> sample code: a function, and a number to be an argument for that function.
> What the heck is the 'name' susposed to be, and how is it not missing in the
> above code?

Usually, you'll make new threads with the new() factory function. This will take
care of the name for you. If you insist on either using the Thread class
directly, you must provide a name (which is only there to make debugging
easier).

In the original version of the uthread module, uthreads weren't objects. It
provided a Thread class, but that was very different from what we have now. In
the current version, the Thread class is always used, but you usually don't
touch it yourself.

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



More information about the Stackless mailing list