Stackless: Recent advancements and future goals

Christian Tismer

Anselm Kruis

What is Stackless?

What is Stackless?

What is Stackless about?

Now, what is it really about?

Cooperative Multitasking

Cooperative Multitasking ...

>>> import stackless
>>>
>>> channel = stackless.channel()
>>> def receiving_tasklet():
...     print "Receiving tasklet started"
...     print channel.receive()
...     print "Receiving tasklet finished"
>>> def sending_tasklet():
...     print "Sending tasklet started"
...     channel.send("send from sending_tasklet")
...     print "sending tasklet finished"

... Cooperative Multitasking ...

>>> def another_tasklet():
...     print "Just another tasklet in the scheduler"
>>> stackless.tasklet(receiving_tasklet)()
<stackless.tasklet object at 0x00A45B30>
>>> stackless.tasklet(sending_tasklet)()
<stackless.tasklet object at 0x00A45B70>
>>> stackless.tasklet(another_tasklet)()
<stackless.tasklet object at 0x00A45BF0>

... Cooperative Multitasking

<stackless.tasklet object at 0x00A45B70>
>>> stackless.tasklet(another_tasklet)()
<stackless.tasklet object at 0x00A45BF0>
>>>
>>> stackless.run()
Receiving tasklet started
Sending tasklet started
send from sending_tasklet
Receiving tasklet finished
Just another tasklet in the scheduler
sending tasklet finished

Why not just the greenlet ?

Excurs: Hard-Switching

Switching program state "the hard way":

Without notice of the interpreter

Excurs: Soft-Switching

Switching program state "the soft way":

With knowledge of the interpreter

Pickling Program State

Pickling Program State

Persistence (p. 1 of 2)

import pickle, sys
import stackless

ch = stackless.channel()

def recurs(depth, level=1):
    print 'enter level %s%d' % (level*'  ', level)
    if level >= depth:
        ch.send('hi')
    if level < depth:
        recurs(depth, level+1)
    print 'leave level %s%d' % (level*'  ', level)

# remember to show it interactively

Pickling Program State

Persistence (p. 2 of 2)

def demo(depth):
    t = stackless.tasklet(recurs)(depth)
    print ch.receive()
    pickle.dump(t, file('tasklet.pickle', 'wb'))

if __name__ == '__main__':
    if len(sys.argv) > 1:
        t = pickle.load(file(sys.argv[1], 'rb'))
        t.insert()
    else:
        t = stackless.tasklet(demo)(9)
    stackless.run()

# remember to show it interactively

Script Output 1

$ ~/src/stackless/python.exe demo/pickledtasklet.py
enter level   1
enter level     2
enter level       3
enter level         4
enter level           5
enter level             6
enter level               7
enter level                 8
enter level                   9
hi
leave level                   9
leave level                 8
leave level               7
leave level             6
leave level           5
leave level         4
leave level       3
leave level     2
leave level   1

Script Output 2

$ ~/src/stackless/python.exe demo/pickledtasklet.py tasklet.pickle
leave level                   9
leave level                 8
leave level               7
leave level             6
leave level           5
leave level         4
leave level       3
leave level     2
leave level   1

Greenlet vs. Stackless

Why Stackless makes a Difference

Persistence, Cloud Computing

What's Stackless good for?

The Stackless Project

The Stackless Project

History of Stackless

The Stackless Project

How can you use Stackless

How can you use Stackless

Recent advancements

Recent advancements

Documentation Updates

Low Level Tasklet Methods

Tasklet Life Cycle

_images/tasklet_lifecycle.png

See also: Stackless manual

Red = new functionality

Tasklet Scheduler

Custom Scheduling

Multithreading - Inter-Thread Scheduling

Subclassing

Important Bug Fixes

Debugging

Better debugger support for Stackless

Future Goals

Immediate future

Later

Goals Or Non Goals

Stackless 2.8

  • Python 2.7.x on Windows still uses VS2008.
  • Possible reasons for a compiler upgrade:
    • 3rd party closed source libraries
    • The insufficent C++ implementation
  • Using a different compiler without changing the name of the python27.dll will cause problems.
  • Christian patched Stackless 2.7 to build with VS2010 and report the version number 2.8.

Discussion: Stackless 2.8 ?