Author: Maciej Fijalkowski <fij...@gmail.com> Branch: extradoc Changeset: r4279:b3b112288b65 Date: 2012-07-04 16:14 +0200 http://bitbucket.org/pypy/extradoc/changeset/b3b112288b65/
Log: merge diff --git a/.hgignore b/.hgignore --- a/.hgignore +++ b/.hgignore @@ -1,3 +1,11 @@ syntax: glob *.py[co] *~ +talk/ep2012/stackless/slp-talk.aux +talk/ep2012/stackless/slp-talk.latex +talk/ep2012/stackless/slp-talk.log +talk/ep2012/stackless/slp-talk.nav +talk/ep2012/stackless/slp-talk.out +talk/ep2012/stackless/slp-talk.snm +talk/ep2012/stackless/slp-talk.toc +talk/ep2012/stackless/slp-talk.vrb \ No newline at end of file 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/eurpython-2012.pptx b/talk/ep2012/stackless/eurpython-2012.pptx new file mode 100644 index 0000000000000000000000000000000000000000..9b34bb66e92cbe27ce5dc5c3928fe9413abf2cef GIT binary patch [cut] 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..afcb8c00b73bb83d114dc4e0d9c8ec1157800ef3 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,675 @@ +.. include:: beamerdefs.txt + +============================================ +The Story of Stackless Python +============================================ + + +About This Talk +---------------- + +* first talk after a long break + + - *rst2beamer* for the first time + +guest speaker: + +* Herve Coatanhay about Nagare + + - PowerPoint (Mac) + +|pause| + +Meanwhile I used + +* Powerpoint (PC) + +* Keynote (Mac) + +* Google Docs + +|pause| + +poll: What is your favorite slide tool? + +What is Stackless? +------------------- + +* *Stackless is a Python version that does not use the C stack* + + |pause| + + - really? naah + +|pause| + +* Stackless is a Python version that does not keep state on the C stack + + - the stack *is* used but + + - cleared between function calls + +|pause| + +* Remark: + + - theoretically. In practice... + + - ... it is reasonable 90 % of the time + + - we come back to this! + + +What is Stackless about? +------------------------- + +* it is like CPython + +|pause| + +* it can do a little bit more + +|pause| + +* adds a single builtin module + +|pause| + +|scriptsize| +|example<| |>| + + .. sourcecode:: python + + import stackless + +|end_example| +|end_scriptsize| + +|pause| + +* is like an extension + + - but, sadly, not really + + - stackless **must** be builtin + + - **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 + + - can partially emulate stackless + + - there is no builtin scheduler + + - technology quite close to Stackless 2.0 + +|pause| + +* greenlets are about 10x slower to switch context because + using only hard-switching + + - but that's ok in most cases + +|pause| + +* greenlets are kind-of perfect + + - near zero maintenace + + - minimal interface + +|pause| + +* but the main difference is ... + + +Excurs: Hard-Switching +----------------------- + +Sorry ;-) + +Switching program state "the hard way": + +Without notice of the interpreter + +* the machine stack gets hijacked + + - Brute-Force: replace the stack with another one + + - like threads + +* stackless, greenlets + + - stack slicing + + - semantically same effect + +* switching works fine + +* pickling does not work, opaque data on the stack + + - this is more sophisticated in PyPy, another story... + + +Excurs: Soft-Switching +----------------------- + +Switching program state "the soft way": + +With knowledge of the interpreter + +* most efficient implementation in Stackless 3.1 + +* demands the most effort of the developers + +* no opaque data on the stack, pickling does work + + - again, this is more sophisticated in PyPy + +|pause| + +* now we are at the main difference, as you guessed ... + + +Pickling Program State +----------------------- + +|scriptsize| +|example<| Persistence (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| + +# *remember to show it interactively* + +|end_scriptsize| + + +Pickling Program State +----------------------- + +|scriptsize| + +|example<| Persistence (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() + + +|end_example| + +# *remember to show it interactively* + +|end_scriptsize| + + +Script Output 1 +----------------- + +|example<| |>| +|scriptsize| + + .. sourcecode:: pycon + + $ ~/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 + +|end_scriptsize| +|end_example| + + +Script Output 2 +----------------- + +|example<| |>| +|scriptsize| + + .. sourcecode:: pycon + + $ ~/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 + +|end_scriptsize| +|end_example| + + +Greenlet vs. Stackless +----------------------- + +* Greenlet is a pure extension module + + - but performance is good enough + +|pause| + +* Stackless can pickle program state + + - but stays a replacement of Python + +|pause| + +* Greenlet never can, as an extension + +|pause| + +* *easy installation* lets people select greenlet over stackless + + - see for example the *eventlet* project + + - *but there is a simple work-around, we'll come to it* + +|pause| + +* *they both have their application domains + and they will persist.* + + +Why Stackless makes a Difference +--------------------------------- + +* Microthreads ? + + - the feature where I put most effort into + + |pause| + + - can be emulated: (in decreasing speed order) + + - generators (incomplete, "half-sided") + + - greenlet + + - threads (even ;-) + +|pause| + +* Pickling program state ! == + +|pause| + +* **persistence** + + +Persistence, Cloud Computing +----------------------------- + +* freeze your running program + +* let it continue anywhere else + + - on a different computer + + - on a different operating system (!) + + - in a cloud + +* migrate your running program + +* save snapshots, have checkpoints + + - without doing any extra-work + + +Software archeology +------------------- + +* Around since 1998 + + - version 1 + + - using only soft-switching + + - continuation-based + + - *please let me skip old design errors :-)* + +|pause| + +* Complete redesign in 2002 + + - version 2 + + - using only hard-switching + + - birth of tasklets and channels + +|pause| + +* 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* (90?) + +* This stayed as version 3.1 + +Status of Stackless Python +--------------------------- + +* mature + +* Python 2 and Python 3, all versions + +* maintained by + + - Richard Tew + - Kristjan Valur Jonsson + - me (a bit) + + +The New Direction for Stackless +------------------------------- + +* ``pip install stackless-python`` + + - will install ``slpython`` + - or even ``python`` (opinions?) + +|pause| + +* drop-in replacement of CPython + *(psssst)* + +|pause| + +* ``pip uninstall stackless-python`` + + - Stackless is a bit cheating, as it replaces the python binary + + - but the user perception will be perfect + +* *trying stackless made easy!* + + +New Direction (cont'd) +----------------------- + +* first prototype yesterday from + + Anselm Kruis *(applause)* + + - works on Windows + + |pause| + + - OS X + + - I'll do that one + + |pause| + + - Linux + + - soon as well + +|pause| + +* being very careful to stay compatible + + - python 2.7.3 installs stackless for 2.7.3 + - python 3.2.3 installs stackless for 3.2.3 + + - python 2.7.2 : *please upgrade* + - or maybe have an over-ride option? + +Consequences of the Pseudo-Package +----------------------------------- + +The technical effect is almost nothing. + +The psycological impact is probably huge: + +|pause| + +* stackless is easy to install and uninstall + +|pause| + +* people can simply try if it fits their needs + +|pause| + +* the never ending discussion + + - "Why is Stackless not included in the Python core?" + +|pause| + +* **has ended** + + - "Why should we, after all?" + + |pause| + + - hey Guido :-) + + - what a relief, for you and me + + +Status of Stackless PyPy +--------------------------- + +* was completely implemented before the Jit + + - together with + greenlets + coroutines + + - not Jit compatible + +* was "too complete" with a 30% performance hit + +* new approach is almost ready + + - with full Jit support + - but needs some fixing + - this *will* be efficient + +Applications using Stackless Python +------------------------------------ + +* The Eve Online MMORPG + + http://www.eveonline.com/ + + - based their games on Stackless since 1998 + +* science + computing ag, Anselm Kruis + + https://ep2012.europython.eu/conference/p/anselm-kruis + +* The Nagare Web Framework + + http://www.nagare.org/ + + - works because of Stackless Pickling + +* today's majority: persistence + + +Thank you +--------- + +* the new Stackless Website + http://www.stackless.com/ + + - a **great** donation from Alain Pourier, *Nagare* + +* You can hire me as a consultant + +* 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} diff --git a/talk/ep2012/stm/stmdemo2.py b/talk/ep2012/stm/stmdemo2.py --- a/talk/ep2012/stm/stmdemo2.py +++ b/talk/ep2012/stm/stmdemo2.py @@ -1,33 +1,37 @@ - def specialize_more_blocks(self): - while True: - # look for blocks not specialized yet - pending = [block for block in self.annotator.annotated - if block not in self.already_seen] - if not pending: - break +def specialize_more_blocks(self): + while True: + # look for blocks not specialized yet + pending = [block for block in self.annotator.annotated + if block not in self.already_seen] + if not pending: + break - # specialize all blocks in the 'pending' list - for block in pending: - self.specialize_block(block) - self.already_seen.add(block) + # specialize all blocks in the 'pending' list + for block in pending: + self.specialize_block(block) + self.already_seen.add(block) - def specialize_more_blocks(self): - while True: - # look for blocks not specialized yet - pending = [block for block in self.annotator.annotated - if block not in self.already_seen] - if not pending: - break - # specialize all blocks in the 'pending' list - # *using transactions* - for block in pending: - transaction.add(self.specialize_block, block) - transaction.run() - self.already_seen.update(pending) + + +def specialize_more_blocks(self): + while True: + # look for blocks not specialized yet + pending = [block for block in self.annotator.annotated + if block not in self.already_seen] + if not pending: + break + + # specialize all blocks in the 'pending' list + # *using transactions* + for block in pending: + transaction.add(self.specialize_block, block) + transaction.run() + + self.already_seen.update(pending) diff --git a/talk/ep2012/stm/talk.pdf b/talk/ep2012/stm/talk.pdf index 19067d178980accc5a060fa819059611fcf1acdc..59ba6454817cd0a87accdf48e505190fe99b4924 GIT binary patch [cut] diff --git a/talk/ep2012/stm/talk.rst b/talk/ep2012/stm/talk.rst --- a/talk/ep2012/stm/talk.rst +++ b/talk/ep2012/stm/talk.rst @@ -484,6 +484,8 @@ * http://pypy.org/ -* You can hire Antonio +* You can hire Antonio (http://antocuni.eu) * Questions? + +* PyPy help desk on Thursday morning \ No newline at end of file diff --git a/talk/vmil2012/paper.tex b/talk/vmil2012/paper.tex --- a/talk/vmil2012/paper.tex +++ b/talk/vmil2012/paper.tex @@ -104,10 +104,10 @@ The contributions of this paper are: \begin{itemize} - \item + \item \end{itemize} -The paper is structured as follows: +The paper is structured as follows: \section{Background} \label{sec:Background} @@ -116,6 +116,34 @@ \label{sub:pypy} +The RPython language and the PyPy Project were started in 2002 with the goal of +creating a python interpreter written in a High level language, allowing easy +language experimentation and extension. PyPy is now a fully compatible +alternative implementation of the Python language, xxx mention speed. The +Implementation takes advantage of the language features provided by RPython +such as the provided tracing just-in-time compiler described below. + +RPython, the language and the toolset originally developed to implement the +Python interpreter have developed into a general environment for experimenting +and developing fast and maintainable dynamic language implementations. xxx Mention +the different language impls. + +RPython is built of two components, the language and the translation toolchain +used to transform RPython programs to executable units. The RPython language +is a statically typed object oriented high level language. The language provides +several features such as automatic memory management (aka. Garbage Collection) +and just-in-time compilation. When writing an interpreter using RPython the +programmer only has to write the interpreter for the language she is +implementing. The second RPython component, the translation toolchain, is used +to transform the program to a low level representations suited to be compiled +and run on one of the different supported target platforms/architectures such +as C, .NET and Java. During the transformation process +different low level aspects suited for the target environment are automatically +added to program such as (if needed) a garbage collector and with some hints +provided by the author a just-in-time compiler. + + + \subsection{PyPy's Meta-Tracing JIT Compilers} \label{sub:tracing} @@ -134,7 +162,7 @@ * High level handling of resumedata * trade-off fast tracing v/s memory usage - * creation in the frontend + * creation in the frontend * optimization * compression * interaction with optimization _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit