[Stackless] Mistakes, Corrections and Questions Re: Stackless Digest, Vol 28, Issue 8

Richard Tew richard.m.tew at gmail.com
Tue May 9 23:17:24 CEST 2006


On 5/9/06, Andrew Francis <andrewfr_ice at yahoo.com> wrote:
> In this scenario I have only unpickled tasklets. I
> know the tasklets must have channel references. I
> don't know how to get the channels from the tasklets?
> I have come to the conclusion that it is best to
> pickle the channels. It may result in a second file,
> but that is a minor inconvenience.

>>> print dir(stackless.tasklet)
... '_channel" ...

> AF> An additional feature I want is the ability of the
> AF> "scheduler" to pickle and unpickle an individual
> AF> "process" blocked on a channel.

This seems to be the state of it at the moment.

It is not possible to remove a tasklet from a channel at
this time without doing so through a send or receive, as
far as I know.

You can only safely pickle a tasklet that is on a channel
if you are also pickling a direct reference to that channel
in the same data that is being passed to dumps or dump.

Given a tasklet "t".  If you pickle it alone, it will get unpickled
with no reference to a channel.  And it will not be unbound
and unrunnable (broken).

If you pickle it like this (t, t._channel), then it will get
unpickled with a reference to the channel.  But the act
of pickling the channel will pickle the other tasklets
blocked on it.

For what you want, you need extra support added to
Stackless which lets tasklets be added and removed
from the channel queue, in the same manner as
insert and remove work on the scheduler.

> so I include the following:
>
> for task in running:
>      task.remove()
>
> and I get
>
...
>
> RuntimeError: You cannot remove a blocked tasklet.

Yes, tasklets that are not scheduled can't be removed
from the scheduler.

>>> print stackless.tasklet.remove.__doc__
Removing a tasklet from the runnables queue.
Note: If this tasklet has a non-trivial C stack attached,
it will be destructed when the containing thread state is destroyed.
Since this will happen in some unpredictable order, it may cause unwanted
side-effects. Therefore it is recommended to either run tasklets to the
end or to explicitly kill() them.

> Okay. I now try the following:
...
> line 67, in __main__
>     channel.send("Hello")
> RuntimeError: Deadlock: the last runnable tasklet
> cannot be blocked.
>
> I thought the main programme would be the last
> runnable tasklet? What I am I doing wrong?

You are in the main program.  You have no other
tasklets, so isn't this exactly like it says?

Why don't you launch the sends in a tasklet?

> The last time I tried the Wiki, I could not add
> material. I would have happy to summarise the
> aforementioned in a Wiki post. I think many readers
> would like to know the use and gotchas
> associated with pickling tasks.

You should be able to edit existing pages with no problem
I believe the problem you would have had is adding new
ones.  And I can do that for you if you email me the name
of the page.

Richard.

_______________________________________________
Stackless mailing list
Stackless at stackless.com
http://www.stackless.com/mailman/listinfo/stackless



More information about the Stackless mailing list