<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
ScratchMonkey wrote:
<blockquote cite="mid225B12DDF7B224BBD4366E43@%5B10.0.0.14%5D"
 type="cite">--On Saturday, June 25, 2005 9:50 PM +0100 Paul Bowsher
<a class="moz-txt-link-rfc2396E" href="mailto:paul.bowsher@gmail.com">&lt;paul.bowsher@gmail.com&gt;</a> wrote:
  <br>
  <blockquote type="cite">Yeah, it's VERY annoying that you have to
restart the server for the
    <br>
new python to take effect. Anyone know if there's an ACTUAL reason for
    <br>
this?
    <br>
  </blockquote>
It's probably like Perl: The code is tokenized and "compiled" to p-code
when&nbsp; initially loaded, and it's the p-code that's "executed". The file
on disk is never looked at again until the interpreter is reloaded.
  <br>
</blockquote>
<div class="moz-text-plain" wrap="true" graphical-quote="true"
 style="font-family: -moz-fixed; font-size: 13px;" lang="x-western">
<pre wrap="">That's all correct, but not why the server has to be restarted. . .

Python does indeed "compile" programs when they are first loaded
(sometimes you'll see ".pyc" files instead of the regular ".py"
files--those are programs that have been saved after having been
tokenized, etc.).

However, Python is a dynamic language, and one property of such
languages is that you can change their code during runtime, while they
are executing.  So, theoretically, there is no reason why you can't have
changes to Python code take effect immediately.

The trick is that you have to write your code with the intention of
allowing this, if it's what you want.  Because people don't normally
change running programs on the fly, Python gains some efficiencies by
assuming you're not going to do it.  For example, if you want to run
code in another module you first have to "import" it.  Python only
imports any given module once--on the assumption that it's not going to
change--so if you do change it and want the changes to take effect, you
can't just import it again; there's a separate "reload" statement that
you have to use if you want to tell Python that the module has changed
and it really should look at your module again.

Part of the problem, too, is that the architecture DICE used assumes
static code; they only import and instantiate objects like
bf2.playerManager once, when the server first starts up, so even if you
change it, and change it's import statement to a "reload", the
bf2.playerManager object has already been created, so changing it's
class has no effect.

There are still ways through this maze--bf2.playerManager, for example,
is just a pointer to an object, so you can assign it to point to a
different object while the program is running, if you want, and then all
method calls against it will go to your new, revised object, like
magic.  This all starts to get pretty twisted, though. . .

So, rather than rewriting everything in tricky ways so that you can
dynamically change the code, given the overall architecture DICE set up,
it's a lot easier (if annoying) to just restart the server.

--Forrest


</pre>
<blockquote type="cite">
  <pre wrap=""><span class="moz-txt-citetags">&gt; </span>--On Saturday, June 25, 2005 9:50 PM +0100 Paul Bowsher
<span class="moz-txt-citetags">&gt; </span><a
 class="moz-txt-link-rfc2396E" href="mailto:paul.bowsher@gmail.com">&lt;paul.bowsher@gmail.com&gt;</a> wrote:
<span class="moz-txt-citetags">&gt;</span>
  </pre>
  <blockquote type="cite">
    <pre wrap=""><span class="moz-txt-citetags">&gt;&gt; </span>Yeah, it's VERY annoying that you have to restart the server for the
<span class="moz-txt-citetags">&gt;&gt; </span>new python to take effect. Anyone know if there's an ACTUAL reason for
<span class="moz-txt-citetags">&gt;&gt; </span>this?
    </pre>
  </blockquote>
  <pre wrap=""><span class="moz-txt-citetags">&gt;</span>
<span class="moz-txt-citetags">&gt;</span>
<span class="moz-txt-citetags">&gt; </span>It's probably like Perl: The code is tokenized and "compiled" to
<span class="moz-txt-citetags">&gt; </span>p-code when  initially loaded, and it's the p-code that's "executed".
<span class="moz-txt-citetags">&gt; </span>The file on disk is never looked at again until the interpreter is
<span class="moz-txt-citetags">&gt; </span>reloaded.
<span class="moz-txt-citetags">&gt;</span>
<span class="moz-txt-citetags">&gt;</span>
  </pre>
</blockquote>
<pre wrap=""><!---->

</pre>
</div>
</body>
</html>