[Stackless] tasklets on threads
Kristján Valur Jónsson
kristjan at ccpgames.com
Thu Sep 8 15:19:30 CEST 2011
Well, we don't keep track of tasklets anywhere.
Even without extra threads, python can exit when there is a tasklet is detached. It may get killed when its final reference goes away, but it has nothing to do with the main thread exiting.
I don't think we ought to have some catalog of tasklets to clean up when a thread goes away. It is always possible for other threads to have access to those tasklets anyway and keep them alive. The only thing that could be done were to have the cstate->tstate somehow magically cleared....
That ought to be possible, with special logic. Keep a list of cstates in the tstate to clear when the tstate dies....
> -----Original Message-----
> From: stackless-bounces at stackless.com [mailto:stackless-
> bounces at stackless.com] On Behalf Of Richard Tew
> Sent: 7. september 2011 23:43
> To: The Stackless Python Mailing List
> Subject: Re: [Stackless] tasklets on threads
> 2011/9/8 Kristján Valur Jónsson <kristjan at ccpgames.com>:
> > I just realized that there are various interesting ways to crash
> > stackless with threads.
> > This one is simple
> > Import treading, stackless
> > Def foo():
> > Global task
> > Task = stackless.getcurrent()
> > Threading.Thread(target=foo).start()
> > ...
> > Task.thread_id
> > This will crash because the other thread's task->cstate is NULL.
> > This is fixable. But what about other cases? Tasklets that are
> > blocked (or
> > removed) when their thread exits?
> > Their task->cstate->tstate will be invalid. And so, there are a
> > number of things that can be done to crash them, like task.insert(), I
> > Should we worry about this? Or should we simply require of the
> > programmer that for safe operation, a thread should exist at least as
> > long as all tasklets created on it, and leave it to the programmer to ensure?
> Do we really have a choice? Is it clean to forceably kill all tasklets belonging to
> a thread when it exits? i.e. raise a TaskletThreadExit exception on them.
> I seem to recall Christian saying that some tasklets could be migrated under
> certain circumstances - presumably if they had not done any hard
> switching. Doesn't sound very useful if some can and some can't,
> unless the programmer is given a choice via a callback when the time comes.
> Stackless mailing list
> Stackless at stackless.com
More information about the Stackless