Author: Christian Tismer <[email protected]> Branch: extradoc Changeset: r4263:bfc42f0b9344 Date: 2012-07-03 13:34 +0200 http://bitbucket.org/pypy/extradoc/changeset/bfc42f0b9344/
Log: first part of my talk, roughly diff --git a/talk/ep2012/stackless/Makefile b/talk/ep2012/stackless/Makefile new file mode 100644 --- /dev/null +++ b/talk/ep2012/stackless/Makefile @@ -0,0 +1,15 @@ +# you can find rst2beamer.py here: +# http://codespeak.net/svn/user/antocuni/bin/rst2beamer.py + +slp-talk.pdf: slp-talk.rst author.latex title.latex stylesheet.latex + rst2beamer.py --stylesheet=stylesheet.latex --documentoptions=14pt slp-talk.rst slp-talk.latex || exit + sed 's/\\date{}/\\input{author.latex}/' -i slp-talk.latex || exit + sed 's/\\maketitle/\\input{title.latex}/' -i slp-talk.latex || exit + sed 's/\\usepackage\[latin1\]{inputenc}/\\usepackage[utf8]{inputenc}/' -i slp-talk.latex || exit + pdflatex slp-talk.latex || exit + +view: slp-talk.pdf + evince talk.pdf & + +xpdf: slp-talk.pdf + xpdf slp-talk.pdf & diff --git a/talk/ep2012/stackless/author.latex b/talk/ep2012/stackless/author.latex new file mode 100644 --- /dev/null +++ b/talk/ep2012/stackless/author.latex @@ -0,0 +1,8 @@ +\definecolor{rrblitbackground}{rgb}{0.0, 0.0, 0.0} + +\title[The Story of Stackless Python]{The Story of Stackless Python} +\author[tismer, nagare] +{Christian Tismer, Hervé Coatanhay} + +\institute{EuroPython 2012} +\date{July 4 2012} diff --git a/talk/ep2012/stackless/beamerdefs.txt b/talk/ep2012/stackless/beamerdefs.txt new file mode 100644 --- /dev/null +++ b/talk/ep2012/stackless/beamerdefs.txt @@ -0,0 +1,108 @@ +.. colors +.. =========================== + +.. role:: green +.. role:: red + + +.. general useful commands +.. =========================== + +.. |pause| raw:: latex + + \pause + +.. |small| raw:: latex + + {\small + +.. |end_small| raw:: latex + + } + +.. |scriptsize| raw:: latex + + {\scriptsize + +.. |end_scriptsize| raw:: latex + + } + +.. |strike<| raw:: latex + + \sout{ + +.. closed bracket +.. =========================== + +.. |>| raw:: latex + + } + + +.. example block +.. =========================== + +.. |example<| raw:: latex + + \begin{exampleblock}{ + + +.. |end_example| raw:: latex + + \end{exampleblock} + + + +.. alert block +.. =========================== + +.. |alert<| raw:: latex + + \begin{alertblock}{ + + +.. |end_alert| raw:: latex + + \end{alertblock} + + + +.. columns +.. =========================== + +.. |column1| raw:: latex + + \begin{columns} + \begin{column}{0.45\textwidth} + +.. |column2| raw:: latex + + \end{column} + \begin{column}{0.45\textwidth} + + +.. |end_columns| raw:: latex + + \end{column} + \end{columns} + + + +.. |snake| image:: ../../img/py-web-new.png + :scale: 15% + + + +.. nested blocks +.. =========================== + +.. |nested| raw:: latex + + \begin{columns} + \begin{column}{0.85\textwidth} + +.. |end_nested| raw:: latex + + \end{column} + \end{columns} diff --git a/talk/ep2012/stackless/demo/pickledtasklet.py b/talk/ep2012/stackless/demo/pickledtasklet.py new file mode 100644 --- /dev/null +++ b/talk/ep2012/stackless/demo/pickledtasklet.py @@ -0,0 +1,25 @@ +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) + +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() diff --git a/talk/ep2012/stackless/logo_small.png b/talk/ep2012/stackless/logo_small.png new file mode 100644 index 0000000000000000000000000000000000000000..acfe083b78f557c394633ca542688a2bfca6a5e8 GIT binary patch [cut] diff --git a/talk/ep2012/stackless/slp-talk.pdf b/talk/ep2012/stackless/slp-talk.pdf new file mode 100644 index 0000000000000000000000000000000000000000..2c75c65e61f2fd5e4a1ffa2986844c62209040f4 GIT binary patch [cut] diff --git a/talk/ep2012/stackless/slp-talk.rst b/talk/ep2012/stackless/slp-talk.rst new file mode 100644 --- /dev/null +++ b/talk/ep2012/stackless/slp-talk.rst @@ -0,0 +1,269 @@ +.. include:: beamerdefs.txt + +============================================ +The Story of Stackless Python +============================================ + +What is Stackless about? +------------------------- + +* it is like CPython + +|pause| + +* it can do a little bit more + +|pause| + +* adds a single module + +|pause| + +|scriptsize| +|example<| |>| + + .. sourcecode:: python + + import stackless + +|end_example| +|end_scriptsize| + +|pause| + +* is like an extension + + - but, sadly, not really + + - **but:** there is a solution... + + +Now, what is it really about? +------------------------------ + +* have tiny little "main" programs + + - ``tasklet`` + +|pause| + +* tasklets communicate via messages + + - ``channel`` + +|pause| + +* tasklets are often called ``microthreads`` + + - but there are no threads at all + + - only one tasklets runs at any time + +|pause| + +* *but see the PyPy STM* approach + + - this will apply to tasklets as well + +Cooperative Multitasking ... +------------------------------- + +|scriptsize| +|example<| |>| + + .. sourcecode:: pycon + + >>> import stackless + >>> + >>> channel = stackless.channel() + +|pause| + + .. sourcecode:: pycon + + >>> def receiving_tasklet(): + ... print "Receiving tasklet started" + ... print channel.receive() + ... print "Receiving tasklet finished" + ... + +|pause| + + .. sourcecode:: pycon + + >>> def sending_tasklet(): + ... print "Sending tasklet started" + ... channel.send("send from sending_tasklet") + ... print "sending tasklet finished" + ... + +|end_example| +|end_scriptsize| + + +Cooperative Multitasking ... +------------------------------- + +|scriptsize| +|example<| |>| + + .. sourcecode:: pycon + + >>> def another_tasklet(): + ... print "Just another tasklet in the scheduler" + ... + +|pause| + + .. sourcecode:: pycon + + >>> 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> + +|end_example| +|end_scriptsize| + + +... Cooperative Multitasking +------------------------------- + +|scriptsize| +|example<| |>| + + .. sourcecode:: pycon + + <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 + +|end_example| +|end_scriptsize| + + +Why not just the *greenlet* ? +------------------------------- + +* greenlets are a subset of stackless + + - there is no scheduler + + - can emulate stackless + +|pause| + +* greenlets are about 5-10x slower to switch + + using only hard-switching + +|pause| + +* but the main difference is ... + + +Pickling Program State +----------------------- + +|scriptsize| +|example<| Example (p. 1 of 2) |>| + + .. sourcecode:: python + + 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) + +|end_example| +|end_scriptsize| + + +Pickling Program State +----------------------- + +|scriptsize| + +|example<| Example (p. 2 of 2) |>| + + .. sourcecode:: python + + + 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 + +|end_example| +|end_scriptsize| + + +Software archeology +------------------- + +* Around since 1998 + + - version 1 + + - using only soft-switching + + - continuation-based + + - *please let me skip old design errors :-)* + +* Complete redesign in 2002 + + - version 2 + + - using only hard-switching + + - birth of tasklets and channels + +* Concept merge in 2004 + + - version 3 + + - **80-20** rule: + + - soft-switching whenever possible + + - hard-switching if foreign code is on the stack + + * these 80 % can be *pickled* + +Thank you +--------- + +* http://pypy.org/ + +* You can hire Antonio + +* Questions? diff --git a/talk/ep2012/stackless/stylesheet.latex b/talk/ep2012/stackless/stylesheet.latex new file mode 100644 --- /dev/null +++ b/talk/ep2012/stackless/stylesheet.latex @@ -0,0 +1,11 @@ +\usetheme{Boadilla} +\usecolortheme{whale} +\setbeamercovered{transparent} +\setbeamertemplate{navigation symbols}{} + +\definecolor{darkgreen}{rgb}{0, 0.5, 0.0} +\newcommand{\docutilsrolegreen}[1]{\color{darkgreen}#1\normalcolor} +\newcommand{\docutilsrolered}[1]{\color{red}#1\normalcolor} + +\newcommand{\green}[1]{\color{darkgreen}#1\normalcolor} +\newcommand{\red}[1]{\color{red}#1\normalcolor} diff --git a/talk/ep2012/stackless/title.latex b/talk/ep2012/stackless/title.latex new file mode 100644 --- /dev/null +++ b/talk/ep2012/stackless/title.latex @@ -0,0 +1,5 @@ +\begin{titlepage} +\begin{figure}[h] +\includegraphics[width=60px]{logo_small.png} +\end{figure} +\end{titlepage} _______________________________________________ pypy-commit mailing list [email protected] http://mail.python.org/mailman/listinfo/pypy-commit
