1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>6. How to use the hotReload feature of CherryPy</title>
<META NAME="description" CONTENT="6. How to use the hotReload feature of CherryPy">
<META NAME="keywords" CONTENT="howto">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="STYLESHEET" href="howto.css" type='text/css'>
<link rel="first" href="howto.html">
<link rel="contents" href="contents.html" title="Contents">
<LINK REL="next" HREF="node8.html">
<LINK REL="previous" HREF="node6.html">
<LINK REL="up" HREF="howto.html">
<LINK REL="next" HREF="node8.html">
<meta name='aesop' content='information'>
</head>
<body>
<DIV CLASS="navigation">
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A HREF="node6.html"><img src="../icons/previous.gif"
border="0" height="32"
alt="Previous Page" width="32"></A></td>
<td><A HREF="howto.html"><img src="../icons/up.gif"
border="0" height="32"
alt="Up One Level" width="32"></A></td>
<td><A HREF="node8.html"><img src="../icons/next.gif"
border="0" height="32"
alt="Next Page" width="32"></A></td>
<td align="center" width="100%">CherryPy HowTo</td>
<td><A HREF="node1.html"><img src="../icons/contents.gif"
border="0" height="32"
alt="Contents" width="32"></A></td>
<td><img src="../icons/blank.gif"
border="0" height="32"
alt="" width="32"></td>
<td><img src="../icons/blank.gif"
border="0" height="32"
alt="" width="32"></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" HREF="node6.html">5. How to compile</A>
<b class="navlabel">Up:</b> <a class="sectref" HREF="howto.html">CherryPy HowTo</A>
<b class="navlabel">Next:</b> <a class="sectref" HREF="node8.html">7. How to use</A>
<br><hr>
</DIV>
<!--End of Navigation Panel-->
<!--Table of Child-Links-->
<A NAME="CHILD_LINKS"><STRONG>Subsections</STRONG></a>
<UL CLASS="ChildLinks">
<LI><A href="node7.html#SECTION007100000000000000000">6.1 Introduction</a>
<LI><A href="node7.html#SECTION007200000000000000000">6.2 How does it work ?</a>
<LI><A href="node7.html#SECTION007300000000000000000">6.3 How to use it ?</a>
</ul>
<!--End of Table of Child-Links-->
<HR>
<H1><A NAME="SECTION007000000000000000000">
6. How to use the hotReload feature of CherryPy</A>
</H1>
<H1><A NAME="SECTION007100000000000000000">
6.1 Introduction</A>
</H1>
The development cycle of a CherryPy web site is the same as the development cycle of a regular software:
<UL>
<LI>Write source files
</LI>
<LI>Compile them
</LI>
<LI>If compiler generated some errors, fix source files and try to compile again
</LI>
<LI>Once compilation was OK, stop running executable and restart the newly generated executable
</LI>
<LI>If we find some bugs or we want some new features, modify the source files and go back to the compilation stage
</LI>
</UL>
<P>
The compilation process is usually pretty fast (if you have a "decent" computer).
<P>
But what if the CherryPy server has a long initialization process (maybe it needs to connect to several ressources,
like databases, or it needs to precompute some data). All this work is usually done in the <var>initServer</var> special
function. If this initialization takes a lot of time, having to stop and restart the server everytime you make
a change is really a loss of time while developing your web site.
<P>
This is where the <var>hotReload</var> feature comes in. It allows you to refresh your code without having to stop
the server.
<P>
<H1><A NAME="SECTION007200000000000000000">
6.2 How does it work ?</A>
</H1>
When it receives a <var>hotReload</var> request, the server will just read its source code again, updating all the CherryClasses
code and recreating new CherryClasses instances with the new code. It will not execute <var>initServer</var> again. Instead,
it will execute <var>hotReloadInitServer</var> if any.
<P>
<H1><A NAME="SECTION007300000000000000000">
6.3 How to use it ?</A>
</H1>
<P>
The <var>hotReload</var> feature is enabled in the executable when the file is compiled with the <var>-D</var> flag (debug mode).
<P>
To send a <var>hotReload</var> request to a running CherryPy server, just use the little script called <span class="file">cherryhotreload.py</span>
provided with the distribution.
<P>
Let's take a practical example that shows how to use the <var>hotReload</var> feature:
<UL>
<LI>You write a first version of your source file called <span class="file">Root.cpy</span>
</LI>
<LI>You compile your source file in debug mode:
<div class="verbatim"><pre>
python ../cherrypy.py -D Root.cpy
</pre></div>
</LI>
<LI>In a window, you start the CherryPy server:
<div class="verbatim"><pre>
python RootServer.py
</pre></div>
</LI>
<LI>Now you have a running CherryPy server
</LI>
<LI>You realize that you want to change something in your code
</LI>
<LI>Just update your source file and recompile it (in another window, since the server is still running in the first window)
</LI>
<LI>Send the <var>hotReload</var> request to the running server to tell it to refresh its code:
<div class="verbatim"><pre>
python cherryhotreload.py localhost:8080
</pre></div>
(This assumes that the server is running on localhost:8080. Of course, you have to adapt it for your own configuration)
</LI>
<LI>In the window where the server is running, you see a message saying that it has performed the <var>hotReload</var>
</LI>
</UL>
Warning: After a <var>hotReload</var>, the line numbers that the python interpreter might give you in case of an error
may not match your source file. This happens if you add or remove lines of code before the <var>hotReload</var>
<P>
<DIV CLASS="navigation">
<p><hr>
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A HREF="node6.html"><img src="../icons/previous.gif"
border="0" height="32"
alt="Previous Page" width="32"></A></td>
<td><A HREF="howto.html"><img src="../icons/up.gif"
border="0" height="32"
alt="Up One Level" width="32"></A></td>
<td><A HREF="node8.html"><img src="../icons/next.gif"
border="0" height="32"
alt="Next Page" width="32"></A></td>
<td align="center" width="100%">CherryPy HowTo</td>
<td><A HREF="node1.html"><img src="../icons/contents.gif"
border="0" height="32"
alt="Contents" width="32"></A></td>
<td><img src="../icons/blank.gif"
border="0" height="32"
alt="" width="32"></td>
<td><img src="../icons/blank.gif"
border="0" height="32"
alt="" width="32"></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" HREF="node6.html">5. How to compile</A>
<b class="navlabel">Up:</b> <a class="sectref" HREF="howto.html">CherryPy HowTo</A>
<b class="navlabel">Next:</b> <a class="sectref" HREF="node8.html">7. How to use</A>
<hr>
<span class="release-info">Release 0.10, documentation updated on 19 March 2004.</span>
</DIV>
<!--End of Navigation Panel-->
<ADDRESS>
See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
</ADDRESS>
</BODY>
</HTML>
|