[Stackless] stackless run_remove()

Kristján Valur Jónsson kristjan at ccpgames.com
Mon Dec 2 17:11:32 CET 2013


Hi, if you look in bitbucket, you'd see that I already created a ticket for it and implemented the fix.
tasklet.switch() immediately runs the target and leaves the caller unscheduled.
This is intended for implementing raw scheduling and does not work inter-thread.

As such, it is similar to run(), except that the caller is left "paused".
stackless.schedule_remove() is a module function because it operates on the stackless
scheduler.  It asks stackless to run the next runnable tasklet.  the "remove" part means that
the caller is left unscheduled.

tasklet.switch() is different from stackless.schedule_remove() in that the former specifies the target
tasklet to which we switch.  

K

> -----Original Message-----
> From: Anselm Kruis [mailto:a.kruis at science-computing.de]
> Sent: 2. desember 2013 15:36
> To: stackless at stackless.com; Kristján Valur Jónsson
> Subject: stackless run_remove()
> 
> Hi,
> 
> I'm currently opening issues to be addressed for 2.7.6-slp. Now I have a
> question about the proposed function/method "run_remove()"
> 
> 1. Is run remove a function in module stackless or a method of class tasklet?
> 
> 2. What's the difference to stackless.schedule_remove()? When to use the
> one, when the other? Could you use schedule_remove() instead of the
> proposed run_remove()?
> 
> I tried:
> -----8<----------8<----------8<----------8<----------8<----------
> $ arch/win32/bin/_fg2python.exe
> Python 2.7.5 Stackless 3.1b3 060516 (default, Nov  6 2013, 18:20:59) [MSC
> v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license"
> for more information.
>  >>> import stackless
>  >>> current=stackless.current
>  >>> def say_hello(): print "Hello, World!"
> ...
>  >>> t=stackless.tasklet(say_hello)()
>  >>> stackless.schedule_remove()
> Hello, World!
> <stackless.tasklet object at 0x02BDC6F0>  >>> current.alive False  >>>
> stackless.current.alive True  >>> stackless.current is current False  >>> t.alive
> False  >>> stackless.current is t False
> -----8<----------8<----------8<----------8<----------8<----------
> 
> So after stackless.schedule_remove() returned we have a new current
> tasklet and the previous current tasklet exited. I'm not sure, if this usage of
> schedule_remove() instead of stackless.run() is correct.
> 
> Cheers
>    Anselm
> 
> 
> Am 19.11.2013 12:16, schrieb Anselm Kruis:
> > Hi Kristján,
> >
> > I wasn't aware of stackless.atomic(). It's not yet documented.
> >
> > Obviously there are a few pending issues before we can release 2.7.6-slp.
> >
> > - add set_args()
> > - add run_remove()
> > - update the documentation
> > - update the changelog
> >
> > Anything else? We should really try to create a consistent and well
> > documented release.
> >
> > Cheers
> >    Anselm
> >
> >
> > Am 19.11.2013 10:16, schrieb Kristján Valur Jónsson:
> >> It does, inasmuch that the implicit "insert" that  exists on many
> >> methods is indeed annoying.
> >> But it is not really a problem, because:
> >>
> >> def set_args(t, args=(), kw={}):
> >>    with stackless.atomic():
> >>      t.setup(*args, **kw):
> >>      t.remove()
> >>
> >>
> >> A more annoying problem that isn't solvable, and that is that there
> >> is no run_remove(), i.e. no way switch to a tasklet and remove the
> >> caller from the run queue.
> >> This is something that is needed in stacklesslib.async:
> >>
> >>
> >> def call_async(callable, args=(), kwargs={}):
> >>      awaiter = Awaiter(stackless.getcurrent())
> >>      callee = stackless.tasklet(async_call_helper)
> >>      future = futures.Future()
> >>      with atomic():
> >>          callee(future, awaiter, callable, args, kwargs)
> >>          try:
> >>              # here, a run(remove=True) or a switch() primitive would
> >> be useful
> >>              callee.run()
> >>          finally:
> >>              # need this here, in case caller gets awoken by other
> >> means, e.g. exception
> >>              awaiter.caller_continued = True
> >>      return future
> >>
> >> def async_call_helper(future, awaiter, callable, args, kwargs):
> >>      # remove the caller from the runnables queue.  There is a window
> >> here where other tasklets
> >>      # might run, we need perhaps a primitive to perform this task
> >>      try:
> >>          awaiter.caller.remove()
> >>
> >>
> 
> --
>   Dipl. Phys. Anselm Kruis                       science + computing ag
>   Senior Solution Architect                      Ingolstädter Str. 22
>   email A.Kruis at science-computing.de             80807 München, Germany
>   phone +49 89 356386 874  fax 737               www.science-computing.de
> --
> Vorstandsvorsitzender/Chairman of the board of management:
> Gerd-Lothar Leonhart
> Vorstand/Board of Management:
> Dr. Bernd Finkbeiner, Michael Heinrichs, Dr. Arno Steitz, Dr. Ingrid Zech
> Vorsitzender des Aufsichtsrats/ Chairman of the Supervisory Board:
> Philippe Miltin
> Sitz/Registered Office: Tuebingen
> Registergericht/Registration Court: Stuttgart Registernummer/Commercial
> Register No.: HRB 382196


More information about the Stackless mailing list