Back to index

moin  1.9.0~rc2
Classes | Functions
MoinMoin.support.werkzeug.serving Namespace Reference

Classes

class  BaseRequestHandler
class  BaseWSGIServer
class  ThreadedWSGIServer
class  ForkingWSGIServer

Functions

def make_server
def reloader_loop
def restart_with_reloader
def run_with_reloader
def run_simple

Function Documentation

def MoinMoin.support.werkzeug.serving.make_server (   host,
  port,
  app = None,
  threaded = False,
  processes = 1,
  request_handler = None,
  passthrough_errors = False 
)
Create a new server instance that is either threaded, or forks
or just processes one request after another.

Definition at line 242 of file serving.py.

00242 
00243                 request_handler=None, passthrough_errors=False):
00244     """Create a new server instance that is either threaded, or forks
00245     or just processes one request after another.
00246     """
00247     if threaded and processes > 1:
00248         raise ValueError("cannot have a multithreaded and "
00249                          "multi process server.")
00250     elif threaded:
00251         return ThreadedWSGIServer(host, port, app, request_handler,
00252                                   passthrough_errors)
00253     elif processes > 1:
00254         return ForkingWSGIServer(host, port, app, processes, request_handler,
00255                                  passthrough_errors)
00256     else:
00257         return BaseWSGIServer(host, port, app, request_handler,
00258                               passthrough_errors)
00259 

Here is the caller graph for this function:

def MoinMoin.support.werkzeug.serving.reloader_loop (   extra_files = None,
  interval = 1 
)
When this function is run from the main thread, it will force other
threads to exit when any modules currently loaded change.

Copyright notice.  This function is based on the autoreload.py from
the CherryPy trac which originated from WSGIKit which is now dead.

:param extra_files: a list of additional files it should watch.

Definition at line 260 of file serving.py.

00260 
00261 def reloader_loop(extra_files=None, interval=1):
00262     """When this function is run from the main thread, it will force other
00263     threads to exit when any modules currently loaded change.
00264 
00265     Copyright notice.  This function is based on the autoreload.py from
00266     the CherryPy trac which originated from WSGIKit which is now dead.
00267 
00268     :param extra_files: a list of additional files it should watch.
00269     """
00270     def iter_module_files():
00271         for module in sys.modules.values():
00272             filename = getattr(module, '__file__', None)
00273             if filename:
00274                 while not os.path.isfile(filename):
00275                     filename = os.path.dirname(filename)
00276                     if not filename:
00277                         break
00278                 else:
00279                     if filename[-4:] in ('.pyc', '.pyo'):
00280                         filename = filename[:-1]
00281                     yield filename
00282 
00283     mtimes = {}
00284     while 1:
00285         for filename in chain(iter_module_files(), extra_files or ()):
00286             try:
00287                 mtime = os.stat(filename).st_mtime
00288             except OSError:
00289                 continue
00290 
00291             old_time = mtimes.get(filename)
00292             if old_time is None:
00293                 mtimes[filename] = mtime
00294                 continue
00295             elif mtime > old_time:
00296                 _log('info', ' * Detected change in %r, reloading' % filename)
00297                 sys.exit(3)
00298         time.sleep(interval)
00299 

Here is the call graph for this function:

Here is the caller graph for this function:

Spawn a new Python interpreter with the same arguments as this one,
but running the reloader thread.

Definition at line 300 of file serving.py.

00300 
00301 def restart_with_reloader():
00302     """Spawn a new Python interpreter with the same arguments as this one,
00303     but running the reloader thread.
00304     """
00305     while 1:
00306         _log('info', ' * Restarting with reloader...')
00307         args = [sys.executable] + sys.argv
00308         new_environ = os.environ.copy()
00309         new_environ['WERKZEUG_RUN_MAIN'] = 'true'
00310         exit_code = subprocess.call(args, env=new_environ)
00311         if exit_code != 3:
00312             return exit_code
00313 

Here is the call graph for this function:

Here is the caller graph for this function:

def MoinMoin.support.werkzeug.serving.run_simple (   hostname,
  port,
  application,
  use_reloader = False,
  use_debugger = False,
  use_evalex = True,
  extra_files = None,
  reloader_interval = 1,
  threaded = False,
  processes = 1,
  request_handler = None,
  static_files = None,
  passthrough_errors = False 
)
Start an application using wsgiref and with an optional reloader.  This
wraps `wsgiref` to fix the wrong default reporting of the multithreaded
WSGI variable and adds optional multithreading and fork support.

.. versionadded:: 0.5
   `static_files` was added to simplify serving of static files as well
   as `passthrough_errors`.

:param hostname: The host for the application.  eg: ``'localhost'``
:param port: The port for the server.  eg: ``8080``
:param application: the WSGI application to execute
:param use_reloader: should the server automatically restart the python
                     process if modules were changed?
:param use_debugger: should the werkzeug debugging system be used?
:param use_evalex: should the exception evaluation feature be enabled?
:param extra_files: a list of files the reloader should watch
                    additionally to the modules.  For example configuration
                    files.
:param reloader_interval: the interval for the reloader in seconds.
:param threaded: should the process handle each request in a separate
                 thread?
:param processes: number of processes to spawn.
:param request_handler: optional parameter that can be used to replace
                        the default one.  You can use this to replace it
                        with a different
                        :class:`~BaseHTTPServer.BaseHTTPRequestHandler`
                        subclass.
:param static_files: a dict of paths for static files.  This works exactly
                     like :class:`SharedDataMiddleware`, it's actually
                     just wrapping the application in that middleware before
                     serving.
:param passthrough_errors: set this to `True` to disable the error catching.
                           This means that the server will die on errors but
                           it can be useful to hook debuggers in (pdb etc.)

Definition at line 332 of file serving.py.

00332 
00333                passthrough_errors=False):
00334     """Start an application using wsgiref and with an optional reloader.  This
00335     wraps `wsgiref` to fix the wrong default reporting of the multithreaded
00336     WSGI variable and adds optional multithreading and fork support.
00337 
00338     .. versionadded:: 0.5
00339        `static_files` was added to simplify serving of static files as well
00340        as `passthrough_errors`.
00341 
00342     :param hostname: The host for the application.  eg: ``'localhost'``
00343     :param port: The port for the server.  eg: ``8080``
00344     :param application: the WSGI application to execute
00345     :param use_reloader: should the server automatically restart the python
00346                          process if modules were changed?
00347     :param use_debugger: should the werkzeug debugging system be used?
00348     :param use_evalex: should the exception evaluation feature be enabled?
00349     :param extra_files: a list of files the reloader should watch
00350                         additionally to the modules.  For example configuration
00351                         files.
00352     :param reloader_interval: the interval for the reloader in seconds.
00353     :param threaded: should the process handle each request in a separate
00354                      thread?
00355     :param processes: number of processes to spawn.
00356     :param request_handler: optional parameter that can be used to replace
00357                             the default one.  You can use this to replace it
00358                             with a different
00359                             :class:`~BaseHTTPServer.BaseHTTPRequestHandler`
00360                             subclass.
00361     :param static_files: a dict of paths for static files.  This works exactly
00362                          like :class:`SharedDataMiddleware`, it's actually
00363                          just wrapping the application in that middleware before
00364                          serving.
00365     :param passthrough_errors: set this to `True` to disable the error catching.
00366                                This means that the server will die on errors but
00367                                it can be useful to hook debuggers in (pdb etc.)
00368     """
00369     if use_debugger:
00370         from werkzeug.debug import DebuggedApplication
00371         application = DebuggedApplication(application, use_evalex)
00372     if static_files:
00373         from werkzeug.utils import SharedDataMiddleware
00374         application = SharedDataMiddleware(application, static_files)
00375 
00376     def inner():
00377         make_server(hostname, port, application, threaded,
00378                     processes, request_handler,
00379                     passthrough_errors).serve_forever()
00380 
00381     if os.environ.get('WERKZEUG_RUN_MAIN') != 'true':
00382         display_hostname = hostname or '127.0.0.1'
00383         _log('info', ' * Running on http://%s:%d/', display_hostname, port)
00384     if use_reloader:
00385         # Create and destroy a socket so that any exceptions are raised before
00386         # we spawn a separate Python interpreter and lose this ability.
00387         test_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
00388         test_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
00389         test_socket.bind((hostname, port))
00390         test_socket.close()
00391         run_with_reloader(inner, extra_files, reloader_interval)
00392     else:
00393         inner()

Here is the call graph for this function:

Here is the caller graph for this function:

def MoinMoin.support.werkzeug.serving.run_with_reloader (   main_func,
  extra_files = None,
  interval = 1 
)
Run the given function in an independent python interpreter.

Definition at line 314 of file serving.py.

00314 
00315 def run_with_reloader(main_func, extra_files=None, interval=1):
00316     """Run the given function in an independent python interpreter."""
00317     if os.environ.get('WERKZEUG_RUN_MAIN') == 'true':
00318         thread.start_new_thread(main_func, ())
00319         try:
00320             reloader_loop(extra_files, interval)
00321         except KeyboardInterrupt:
00322             return
00323     try:
00324         sys.exit(restart_with_reloader())
00325     except KeyboardInterrupt:
00326         pass
00327 

Here is the call graph for this function:

Here is the caller graph for this function: