Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does Google App Engine dev_appserver.py serve fresh content without restarting?

One of the things I like about Google App Engine development environment is, I don't have to restart the server every time I make changes to any python source files, other static files or even configuration files. It has spoilt me and I forget to restart the server when I am working with other server environments (tornadoweb, web.py, node.js).

Can anyone explain how GAE does that? How difficult is it to make other servers (at least python based) to achieve the same thing?

like image 929
Jayesh Avatar asked May 13 '11 01:05

Jayesh


2 Answers

You can view the source for dev_appserver.py(link). Looks like ModuleManager makes a copy of sys.modules and monitors each module to track changes based on time:

class ModuleManager(object):
  """Manages loaded modules in the runtime.

  Responsible for monitoring and reporting about file modification times.
  Modules can be loaded from source or precompiled byte-code files.  When a
  file has source code, the ModuleManager monitors the modification time of
  the source file even if the module itself is loaded from byte-code.
  """

http://code.google.com/p/googleappengine/source/browse/trunk/python/google/appengine/tools/dev_appserver.py#3636

like image 198
hyperslug Avatar answered Oct 05 '22 22:10

hyperslug


Lot of webservers like GAE, make use of python reload module to see the effect in code change without restarting the server process

import something

if is_changed(something)
   somthing = reload(something)

Quote from python docs: When reload(module) is executed:

Python modules’ code is recompiled and the module-level code reexecuted, defining a new set of objects which are bound to names in the module’s dictionary. The init function of extension modules is not called a second time.

As with all other objects in Python the old objects are only reclaimed after their reference counts drop to zero.

The names in the module namespace are updated to point to any new or changed objects. Other references to the old objects (such as names external to the module) are not rebound to refer to the new objects and must be updated in each namespace where they occur if that is desired.

like image 25
Abdul Kader Avatar answered Oct 05 '22 23:10

Abdul Kader