Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

add Sphinx documentation, closes gh-3

  • Loading branch information...
commit a9d872736aa2b69c5a88881714fa8341056335f8 1 parent 6fcfbfd
Evan Klitzke eklitzke authored
1  .gitignore
@@ -3,3 +3,4 @@
3 3 current
4 4 tmp_*
5 5 zygote.egg-info
  6 +docs/build
5 Makefile
... ... @@ -1,4 +1,4 @@
1   -.PHONY: pyflakes clean test production
  1 +.PHONY: pyflakes clean test production docs
2 2
3 3 pyflakes:
4 4 find . -name '*.py' -print0 | xargs -0 pyflakes
@@ -14,3 +14,6 @@ serviceinit.d:
14 14 mkdir serviceinit.d
15 15
16 16 production: serviceinit.d
  17 +
  18 +docs:
  19 + make -C docs html
1  README.rst
Source Rendered
130 docs/Makefile
... ... @@ -0,0 +1,130 @@
  1 +# Makefile for Sphinx documentation
  2 +#
  3 +
  4 +# You can set these variables from the command line.
  5 +SPHINXOPTS =
  6 +SPHINXBUILD = sphinx-build
  7 +PAPER =
  8 +BUILDDIR = build
  9 +
  10 +# Internal variables.
  11 +PAPEROPT_a4 = -D latex_paper_size=a4
  12 +PAPEROPT_letter = -D latex_paper_size=letter
  13 +ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source
  14 +
  15 +.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest
  16 +
  17 +help:
  18 + @echo "Please use \`make <target>' where <target> is one of"
  19 + @echo " html to make standalone HTML files"
  20 + @echo " dirhtml to make HTML files named index.html in directories"
  21 + @echo " singlehtml to make a single large HTML file"
  22 + @echo " pickle to make pickle files"
  23 + @echo " json to make JSON files"
  24 + @echo " htmlhelp to make HTML files and a HTML help project"
  25 + @echo " qthelp to make HTML files and a qthelp project"
  26 + @echo " devhelp to make HTML files and a Devhelp project"
  27 + @echo " epub to make an epub"
  28 + @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
  29 + @echo " latexpdf to make LaTeX files and run them through pdflatex"
  30 + @echo " text to make text files"
  31 + @echo " man to make manual pages"
  32 + @echo " changes to make an overview of all changed/added/deprecated items"
  33 + @echo " linkcheck to check all external links for integrity"
  34 + @echo " doctest to run all doctests embedded in the documentation (if enabled)"
  35 +
  36 +clean:
  37 + -rm -rf $(BUILDDIR)/*
  38 +
  39 +html:
  40 + $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
  41 + @echo
  42 + @echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
  43 +
  44 +dirhtml:
  45 + $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
  46 + @echo
  47 + @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml."
  48 +
  49 +singlehtml:
  50 + $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml
  51 + @echo
  52 + @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml."
  53 +
  54 +pickle:
  55 + $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle
  56 + @echo
  57 + @echo "Build finished; now you can process the pickle files."
  58 +
  59 +json:
  60 + $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json
  61 + @echo
  62 + @echo "Build finished; now you can process the JSON files."
  63 +
  64 +htmlhelp:
  65 + $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp
  66 + @echo
  67 + @echo "Build finished; now you can run HTML Help Workshop with the" \
  68 + ".hhp project file in $(BUILDDIR)/htmlhelp."
  69 +
  70 +qthelp:
  71 + $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp
  72 + @echo
  73 + @echo "Build finished; now you can run "qcollectiongenerator" with the" \
  74 + ".qhcp project file in $(BUILDDIR)/qthelp, like this:"
  75 + @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/Zygote.qhcp"
  76 + @echo "To view the help file:"
  77 + @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/Zygote.qhc"
  78 +
  79 +devhelp:
  80 + $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp
  81 + @echo
  82 + @echo "Build finished."
  83 + @echo "To view the help file:"
  84 + @echo "# mkdir -p $$HOME/.local/share/devhelp/Zygote"
  85 + @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/Zygote"
  86 + @echo "# devhelp"
  87 +
  88 +epub:
  89 + $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub
  90 + @echo
  91 + @echo "Build finished. The epub file is in $(BUILDDIR)/epub."
  92 +
  93 +latex:
  94 + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
  95 + @echo
  96 + @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex."
  97 + @echo "Run \`make' in that directory to run these through (pdf)latex" \
  98 + "(use \`make latexpdf' here to do that automatically)."
  99 +
  100 +latexpdf:
  101 + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
  102 + @echo "Running LaTeX files through pdflatex..."
  103 + make -C $(BUILDDIR)/latex all-pdf
  104 + @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
  105 +
  106 +text:
  107 + $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text
  108 + @echo
  109 + @echo "Build finished. The text files are in $(BUILDDIR)/text."
  110 +
  111 +man:
  112 + $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man
  113 + @echo
  114 + @echo "Build finished. The manual pages are in $(BUILDDIR)/man."
  115 +
  116 +changes:
  117 + $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes
  118 + @echo
  119 + @echo "The overview file is in $(BUILDDIR)/changes."
  120 +
  121 +linkcheck:
  122 + $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck
  123 + @echo
  124 + @echo "Link check complete; look for any errors in the above output " \
  125 + "or in $(BUILDDIR)/linkcheck/output.txt."
  126 +
  127 +doctest:
  128 + $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
  129 + @echo "Testing of doctests in the sources finished, look at the " \
  130 + "results in $(BUILDDIR)/doctest/output.txt."
216 docs/source/conf.py
... ... @@ -0,0 +1,216 @@
  1 +# -*- coding: utf-8 -*-
  2 +#
  3 +# Zygote documentation build configuration file, created by
  4 +# sphinx-quickstart on Fri Jun 24 18:18:33 2011.
  5 +#
  6 +# This file is execfile()d with the current directory set to its containing dir.
  7 +#
  8 +# Note that not all possible configuration values are present in this
  9 +# autogenerated file.
  10 +#
  11 +# All configuration values have a default; values that are commented out
  12 +# serve to show the default.
  13 +
  14 +import sys, os
  15 +
  16 +# If extensions (or modules to document with autodoc) are in another directory,
  17 +# add these directories to sys.path here. If the directory is relative to the
  18 +# documentation root, use os.path.abspath to make it absolute, like shown here.
  19 +#sys.path.insert(0, os.path.abspath('.'))
  20 +
  21 +# -- General configuration -----------------------------------------------------
  22 +
  23 +# If your documentation needs a minimal Sphinx version, state it here.
  24 +#needs_sphinx = '1.0'
  25 +
  26 +# Add any Sphinx extension module names here, as strings. They can be extensions
  27 +# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
  28 +extensions = []
  29 +
  30 +# Add any paths that contain templates here, relative to this directory.
  31 +templates_path = ['_templates']
  32 +
  33 +# The suffix of source filenames.
  34 +source_suffix = '.rst'
  35 +
  36 +# The encoding of source files.
  37 +#source_encoding = 'utf-8-sig'
  38 +
  39 +# The master toctree document.
  40 +master_doc = 'index'
  41 +
  42 +# General information about the project.
  43 +project = u'Zygote'
  44 +copyright = u'2011, Evan Klitzke'
  45 +
  46 +# The version info for the project you're documenting, acts as replacement for
  47 +# |version| and |release|, also used in various other places throughout the
  48 +# built documents.
  49 +#
  50 +# The short X.Y version.
  51 +version = '0.1.0'
  52 +# The full version, including alpha/beta/rc tags.
  53 +release = '0.1.0'
  54 +
  55 +# The language for content autogenerated by Sphinx. Refer to documentation
  56 +# for a list of supported languages.
  57 +#language = None
  58 +
  59 +# There are two options for replacing |today|: either, you set today to some
  60 +# non-false value, then it is used:
  61 +#today = ''
  62 +# Else, today_fmt is used as the format for a strftime call.
  63 +#today_fmt = '%B %d, %Y'
  64 +
  65 +# List of patterns, relative to source directory, that match files and
  66 +# directories to ignore when looking for source files.
  67 +exclude_patterns = []
  68 +
  69 +# The reST default role (used for this markup: `text`) to use for all documents.
  70 +#default_role = None
  71 +
  72 +# If true, '()' will be appended to :func: etc. cross-reference text.
  73 +#add_function_parentheses = True
  74 +
  75 +# If true, the current module name will be prepended to all description
  76 +# unit titles (such as .. function::).
  77 +#add_module_names = True
  78 +
  79 +# If true, sectionauthor and moduleauthor directives will be shown in the
  80 +# output. They are ignored by default.
  81 +#show_authors = False
  82 +
  83 +# The name of the Pygments (syntax highlighting) style to use.
  84 +pygments_style = 'sphinx'
  85 +
  86 +# A list of ignored prefixes for module index sorting.
  87 +#modindex_common_prefix = []
  88 +
  89 +
  90 +# -- Options for HTML output ---------------------------------------------------
  91 +
  92 +# The theme to use for HTML and HTML Help pages. See the documentation for
  93 +# a list of builtin themes.
  94 +html_theme = 'default'
  95 +
  96 +# Theme options are theme-specific and customize the look and feel of a theme
  97 +# further. For a list of options available for each theme, see the
  98 +# documentation.
  99 +#html_theme_options = {}
  100 +
  101 +# Add any paths that contain custom themes here, relative to this directory.
  102 +#html_theme_path = []
  103 +
  104 +# The name for this set of Sphinx documents. If None, it defaults to
  105 +# "<project> v<release> documentation".
  106 +#html_title = None
  107 +
  108 +# A shorter title for the navigation bar. Default is the same as html_title.
  109 +#html_short_title = None
  110 +
  111 +# The name of an image file (relative to this directory) to place at the top
  112 +# of the sidebar.
  113 +#html_logo = None
  114 +
  115 +# The name of an image file (within the static path) to use as favicon of the
  116 +# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
  117 +# pixels large.
  118 +#html_favicon = None
  119 +
  120 +# Add any paths that contain custom static files (such as style sheets) here,
  121 +# relative to this directory. They are copied after the builtin static files,
  122 +# so a file named "default.css" will overwrite the builtin "default.css".
  123 +html_static_path = ['_static']
  124 +
  125 +# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
  126 +# using the given strftime format.
  127 +#html_last_updated_fmt = '%b %d, %Y'
  128 +
  129 +# If true, SmartyPants will be used to convert quotes and dashes to
  130 +# typographically correct entities.
  131 +#html_use_smartypants = True
  132 +
  133 +# Custom sidebar templates, maps document names to template names.
  134 +#html_sidebars = {}
  135 +
  136 +# Additional templates that should be rendered to pages, maps page names to
  137 +# template names.
  138 +#html_additional_pages = {}
  139 +
  140 +# If false, no module index is generated.
  141 +#html_domain_indices = True
  142 +
  143 +# If false, no index is generated.
  144 +#html_use_index = True
  145 +
  146 +# If true, the index is split into individual pages for each letter.
  147 +#html_split_index = False
  148 +
  149 +# If true, links to the reST sources are added to the pages.
  150 +#html_show_sourcelink = True
  151 +
  152 +# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
  153 +#html_show_sphinx = True
  154 +
  155 +# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
  156 +#html_show_copyright = True
  157 +
  158 +# If true, an OpenSearch description file will be output, and all pages will
  159 +# contain a <link> tag referring to it. The value of this option must be the
  160 +# base URL from which the finished HTML is served.
  161 +#html_use_opensearch = ''
  162 +
  163 +# This is the file name suffix for HTML files (e.g. ".xhtml").
  164 +#html_file_suffix = None
  165 +
  166 +# Output file base name for HTML help builder.
  167 +htmlhelp_basename = 'Zygotedoc'
  168 +
  169 +
  170 +# -- Options for LaTeX output --------------------------------------------------
  171 +
  172 +# The paper size ('letter' or 'a4').
  173 +#latex_paper_size = 'letter'
  174 +
  175 +# The font size ('10pt', '11pt' or '12pt').
  176 +#latex_font_size = '10pt'
  177 +
  178 +# Grouping the document tree into LaTeX files. List of tuples
  179 +# (source start file, target name, title, author, documentclass [howto/manual]).
  180 +latex_documents = [
  181 + ('index', 'Zygote.tex', u'Zygote Documentation',
  182 + u'Evan Klitzke', 'manual'),
  183 +]
  184 +
  185 +# The name of an image file (relative to this directory) to place at the top of
  186 +# the title page.
  187 +#latex_logo = None
  188 +
  189 +# For "manual" documents, if this is true, then toplevel headings are parts,
  190 +# not chapters.
  191 +#latex_use_parts = False
  192 +
  193 +# If true, show page references after internal links.
  194 +#latex_show_pagerefs = False
  195 +
  196 +# If true, show URL addresses after external links.
  197 +#latex_show_urls = False
  198 +
  199 +# Additional stuff for the LaTeX preamble.
  200 +#latex_preamble = ''
  201 +
  202 +# Documents to append as an appendix to all manuals.
  203 +#latex_appendices = []
  204 +
  205 +# If false, no module index is generated.
  206 +#latex_domain_indices = True
  207 +
  208 +
  209 +# -- Options for manual page output --------------------------------------------
  210 +
  211 +# One entry per manual page. List of tuples
  212 +# (source start file, name, description, authors, manual section).
  213 +man_pages = [
  214 + ('index', 'zygote', u'Zygote Documentation',
  215 + [u'Evan Klitzke'], 1)
  216 +]
141 README.md → docs/source/index.rst
Source Rendered
@@ -10,27 +10,27 @@ Let's say you're serving your application, and the currently deployed version is
10 10 called `A`. You're trying to deploy a new version of your web app, and that
11 11 version is called `B`. The way you want it to work is like this:
12 12
13   - * A new Python interpreter `P` starts up, imports code from `B` and does all of
14   - the static initialization and loads modules. This process should only happen
15   - once.
16   -
17   - * New HTTP workers are created by forking `P`. That way new workers don't need
18   - to reimport lots of code (so starting a worker is significantly cheaper in
19   - terms of disk I/O and CPU time), and workers can share static data structures
20   - (so starting a new worker consumes significantly less memory).
21   -
22   - * In progress requests that are being run from the `A` version of the code
23   - should be allowed to complete, and not be interrupted; deploying new code
24   - should not cause anyone to get an HTTP 500 response, or even be noticeable by
25   - users.
26   -
27   - * The deploy code needs to be cognizant of how many HTTP workers the system is
28   - capable of running (usually this means don't run more workers than you have
29   - RAM allocated for), so if a machine is capable of supporting 200 workers, and
30   - 100 of them are serving requests for `A` at the time of the deploy, at first
31   - the 100 idle `A` workers can be killed and 100 `B` workers can be spawned,
32   - and then `A` workers are killed and `B` workers are spawned as the `A`
33   - workers complete their requests.
  13 +* A new Python interpreter `P` starts up, imports code from `B` and does all of
  14 + the static initialization and loads modules. This process should only happen
  15 + once.
  16 +
  17 +* New HTTP workers are created by forking `P`. That way new workers don't need
  18 + to reimport lots of code (so starting a worker is significantly cheaper in
  19 + terms of disk I/O and CPU time), and workers can share static data structures
  20 + (so starting a new worker consumes significantly less memory).
  21 +
  22 +* In progress requests that are being run from the `A` version of the code
  23 + should be allowed to complete, and not be interrupted; deploying new code
  24 + should not cause anyone to get an HTTP 500 response, or even be noticeable by
  25 + users.
  26 +
  27 +* The deploy code needs to be cognizant of how many HTTP workers the system is
  28 + capable of running (usually this means don't run more workers than you have
  29 + RAM allocated for), so if a machine is capable of supporting 200 workers, and
  30 + 100 of them are serving requests for `A` at the time of the deploy, at first
  31 + the 100 idle `A` workers can be killed and 100 `B` workers can be spawned,
  32 + and then `A` workers are killed and `B` workers are spawned as the `A`
  33 + workers complete their requests.
34 34
35 35 This is what Zygote does. Zygote has an embedded HTTP server based on the one
36 36 provided by Tornado, but this is complementary to a real, full-fledged HTTP
@@ -38,21 +38,21 @@ server like Apache or Nginx -- Zygote's expertise is just in managing Python web
38 38 processes. It's OK to run Apache or Nginx in front of Zygote.
39 39
40 40 Zygote is licensed under the
41   -[Apache Licence, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0.html). You
  41 +`Apache Licence, Version 2.0 <http://www.apache.org/licenses/LICENSE-2.0.html>`_. You
42 42 should find a copy of this license along with the Zygote source, in the
43   -`LICENSE` file.
  43 +``LICENSE`` file.
44 44
45 45 How It Works
46 46 ------------
47 47
48 48 The concept of "zygote" processes on Unix systems is not new; see Chromium's
49   -[LinuxZygote](http://code.google.com/p/chromium/wiki/LinuxZygote) wiki page for
  49 +`LinuxZygote <http://code.google.com/p/chromium/wiki/LinuxZygote>`_ wiki page for
50 50 a description of how they're used in the Chromium browser. In the Zygote process
51   -model there is a process tree that looks something like this:
  51 +model there is a process tree that looks something like this::
52 52
53 53 zygote-master
54   - \
55   - `--- zygote A
  54 + \
  55 + `--- zygote A
56 56 | `--- worker
57 57 | --- worker
58 58 |
@@ -79,7 +79,7 @@ fork.
79 79 Internally, communication between the different processes is done using abstract
80 80 unix domain sockets.
81 81
82   -If you use a command like `pstree` or `ps -eFH` you can verify that the process
  82 +If you use a command like ``pstree`` or ``ps -eFH`` you can verify that the process
83 83 tree looks as expected. Additionally, if you have the `setproctitle` Python
84 84 module available, the processes will set their titles such that it's easy to see
85 85 what version of the code everything is running.
@@ -89,31 +89,32 @@ How to Use It
89 89
90 90 To use Zygote, you need to write a module that implements a `get_application`
91 91 method. That method takes no arguments, and returns an object that can be used
92   -by a [Tornado](http://www.tornadoweb.org/) HTTPServer object (typically this
  92 +by a `Tornado <http://www.tornadoweb.org/>`_ HTTPServer object (typically this
93 93 would be an instance of `tornado.web.Application`).
94 94
95   -After that, an invocation of Zygote would be done like this:
  95 +After that, an invocation of Zygote would be done like this::
96 96
97 97 python -m zygote.main -p 8000 -b ./example example
98 98
99   -Let's break that down. The `python -m zygote.main` part instructs Python to run
100   -Zygote's `main` module. The parts after that are options and arguments. The `-p
101   -8000` option instructs Zygote that your application will be served from port
102   -8000. The `-b ./example` option states that the symlink for your application
103   -exists at `./example`. This does not strictly need to be a symlink, but the code
104   -versioning will only work if it is a symlink. The final argument is just
105   -`example` and that states that the module name for the application is `example`.
  99 +Let's break that down. The ``python -m zygote.main`` part instructs Python to
  100 +run Zygote's `main` module. The parts after that are options and arguments. The
  101 +``-p 8000`` option instructs Zygote that your application will be served from
  102 +port 8000. The ``-b ./example`` option states that the symlink for your
  103 +application exists at ``./example``. This does not strictly need to be a symlink,
  104 +but the code versioning will only work if it is a symlink. The final argument is
  105 +just ``example`` and that states that the module name for the application is
  106 +``example``.
106 107
107 108 The example invocation given above will work if you run it from a clone of the
108   -Zygote source code. The `-b` option tells Zygote what to insert into `sys.path`
  109 +Zygote source code. The ``-b`` option tells Zygote what to insert into `sys.path`
109 110 to make your code runnable, and in the Zygote source tree there's a file named
110   -`example/example.py`. In other words, `example` gets added to `sys.path` and
111   -that makes `example.py` importable by doing `import example`.
  111 +``example/example.py``. In other words, `example` gets added to `sys.path` and
  112 +that makes ``example.py`` importable by doing ``import example``.
112 113
113 114 Caveats
114 115 -------
115 116
116   -Currently Zygote only works with [Tornado](http://www.tornadoweb.org/)
  117 +Currently Zygote only works with `Tornado <http://www.tornadoweb.org/>`_
117 118 applications. It should be fairly straightforward to get it working with other
118 119 WSGI webservers, however. It just requires someone whose willing to roll their
119 120 sleeves up and hack on the code a bit.
@@ -131,61 +132,65 @@ need.
131 132 Process Protocol
132 133 ----------------
133 134
134   -The zygote master opens an abstract unix domain socket with a name like this:
  135 +The zygote master opens an abstract unix domain socket with a name like this::
  136 +
135 137 '\0' + "zygote_" + pid_of_master
136   -Messages to the master have the following format:
  138 +
  139 +Messages to the master have the following format::
  140 +
137 141 str(pid_of_sender) + ' ' + msg_type + ' ' + msg_body
138   -The msg_type is a single byte, by convention it corresponds to an actual ASCII
139   -character. See `zygote/message.py` for the different message types.
140 142
141   -The master spawns zygotes. A zygote supports two signals. Sending it `SIGTERM`
142   -instructs it to exit. Sending the zygote `SIGUSR1` instructs the zygote to fork
143   -and start a worker process. The worker processes communicate to the zygote
  143 +The ``msg_type`` is a single byte, by convention it corresponds to an actual
  144 +ASCII character. See ``zygote/message.py`` for the different message types.
  145 +
  146 +The master spawns zygotes. A zygote supports two signals. Sending it ``SIGTERM``
  147 +instructs it to exit. Sending the zygote ``SIGUSR1`` instructs the zygote to
  148 +fork and start a worker process. The worker processes communicate to the zygote
144 149 master using the aforementioned abstract unix domain socket.
145 150
146   -Sending `SIGINT` or `SIGTERM` to a worker causes it to exit with status 0.
  151 +Sending ``SIGINT`` or ``SIGTERM`` to a worker causes it to exit with status 0.
147 152
148 153 When a worker is spawned, it will send a "spawn" message to the master, signaled
149   -by `S`. The body of the "spawn" message is the PPID of the worker (i.e. the PID
150   -of the zygote that spawned the worker).
  154 +by ``S``. The body of the "spawn" message is the PPID of the worker (i.e. the
  155 +PID of the zygote that spawned the worker).
151 156
152 157 When a worker exits, its parent will send an "exit" message to the master,
153   -signaled by `X`. The body of the message will be of the format
154   -`str(pid_of_worker) + ' ' + str(exit_status)`. The master process will decide
155   -whether the zygote should respawn the worker or not (by sending `SIGUSR1` to the
156   -zygote if the worker should be respawned).
  158 +signaled by ``X``. The body of the message will be of the format
  159 +``str(pid_of_worker) + ' ' + str(exit_status)``. The master process will decide
  160 +whether the zygote should respawn the worker or not (by sending ``SIGUSR1`` to
  161 +the zygote if the worker should be respawned).
157 162
158 163 When a worker begins processing an HTTP request, it will send a "begin http"
159   -message, signaled by `B`. The body of the message will contain the request
160   -string sent by the client, so it will be something like `GET / HTTP/1.1`.
  164 +message, signaled by ``B``. The body of the message will contain the request
  165 +string sent by the client, so it will be something like ``GET / HTTP/1.1``.
161 166
162 167 When a worker finishes processing an HTTP request, it will send an "end http"
163   -message, signaled by `E`. There is no body.
  168 +message, signaled by ``E``. There is no body.
164 169
165 170 While all of this is going on, the master processes operates a simple state
166 171 machine to keep track of the current status of all of the zygotes and worker
167 172 processes. It's up to the master process to know when it's safe to gracefully
168 173 kill a worker (which it can tell because the last message from the worker was an
169   -`S` or an `E`). It's up to the master process to keep track of how many requests
170   -a worker has processed, and whether that means the worker should be killed (and
171   -respawned). And so on. The implicit goal of this is that all complicated process
172   -management logic should exist in the zygote master; there should be very little
173   -logic in the zygotes, or in the worker children.
  174 +``S`` or an ``E``). It's up to the master process to keep track of how many
  175 +requests a worker has processed, and whether that means the worker should be
  176 +killed (and respawned). And so on. The implicit goal of this is that all
  177 +complicated process management logic should exist in the zygote master; there
  178 +should be very little logic in the zygotes, or in the worker children.
174 179
175 180 Testing
176 181 -------
177 182
178   -There are unit tests, which exist in the `tests` directory. You should be able
179   -to run them by invoking `make test`, e.g.
  183 +There are unit tests, which exist in the ``tests`` directory. You should be able
  184 +to run them by invoking ``make test``, e.g.::
180 185
181 186 evan@zeno ~/code/zygote (master) $ make test
182 187 tests.test ZygoteTests.test_http_get ... ok in 2.53s
183 188
184 189 PASSED. 1 test / 1 case: 1 passed (0 unexpected), 0 failed (0 expected). (Total test time 2.53s)
185 190
186   -Some caveats. You need a very recent version of `tornado` to run the tests. This
  191 +Some caveats. You need a very recent version of Tornado to run the tests. This
187 192 is to force Tornado to use the "simple" http client. Hopefully the API will be
188   -stable going forward from Tornado 0.2.0ñ.
  193 +stable going forward from Tornado 0.2.0.
189 194
190   -You will also need [testify](http://pypi.python.org/pypi/testify/) to run the
  195 +You will also need `Testify <http://pypi.python.org/pypi/testify/>`_ to run the
191 196 tests. Any version of Testify should work.

0 comments on commit a9d8727

Please sign in to comment.
Something went wrong with that request. Please try again.