[Stackless] Newbie Stackless Question
James Turner
jamwt at jamwt.com
Wed Apr 11 19:22:44 CEST 2001
Hi there,
> I'm working on a new project, and have decided that Stackless is
> probably best for my needs, since ideally I wish to keep memory and CPU use
> to a minimum. Apparently microthreads will do the memory bit; I have no idea
> if its more CPU intensive or not. This is not URGENT, its just a strong
> preference.
In my experiences using uthreads, CPU *and* memory are extremely well
conserved--there is little overhead switching between microthreads
because they don't need a stack context switch. However, I've found
sometimes you have to play tricks with your program to make I/O work
properly--the lib will sometimes exit all threads if they happen
to be all waiting on socket I/O or something at the same time,
thinking that there is no more work left to do.
> Here's my question: All of the examples in the uthread homepage show the
> creation of the threads all at once, then a final 'uthread.run()' to
> actually do everything. Almost all of my threads will be loops, and will be
> long-running. Further, I won't know how many to create when I start the
> application.
>
> Is there a way to add a thread in the middle of an application's run,
> after we've already done a uthread.run()?
I don't believe so. You of course have runAndContinue(), but you still
can't add more after you've already launched your microthreads.
This is just from my experience--there are *many* people on this list
that are more knowledgeable than I and may be able to correct me
here. If so, please do, because I to would love to be able to do
something similar to thread.start_new_thread(func,(args,)) using
uthreads.
With normal threads, I'd never recommend this, but it may be
suitable in your case: If there's a reasonable maximum number of
threads you need, run that amount. You say 'dozens of microthreads';
well you can easily have hundreds or more, and each one won't
schedule up until it has finished wait()ing, or poll()ing, or
whatever--you can still hum along efficient with resources with
even hundreds of microthreads waiting to do your bidding.
Hope some of this helps.
--James
_______________________________________________
Stackless mailing list
Stackless at starship.python.net
http://starship.python.net/mailman/listinfo/stackless
More information about the Stackless
mailing list