当前位置: 首页>>代码示例>>Python>>正文


Python WSGIServer.run方法代码示例

本文整理汇总了Python中flup.server.fcgi.WSGIServer.run方法的典型用法代码示例。如果您正苦于以下问题:Python WSGIServer.run方法的具体用法?Python WSGIServer.run怎么用?Python WSGIServer.run使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在flup.server.fcgi.WSGIServer的用法示例。


在下文中一共展示了WSGIServer.run方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from flup.server.fcgi import WSGIServer [as 别名]
# 或者: from flup.server.fcgi.WSGIServer import run [as 别名]
def main():
    app = create_app()

    log_fmt = logging.Formatter("[%(asctime)s] %(module)s "
                                "%(levelname)s %(message)s")

    suggestion_log_path = os.path.join(app.instance_path, 'database.log')
    suggestion_handler = logging.FileHandler(suggestion_log_path)
    suggestion_handler.setFormatter(log_fmt)
    database.log.addHandler(suggestion_handler)

    import sys
    if len(sys.argv) > 1:
        cmd = sys.argv[1]
    else:
        cmd = 'runserver'

    if cmd == 'runserver':
        app.run(debug=True)
    elif cmd == 'shell':
        from code import interact
        with app.test_request_context():
            interact(local={'app': app})
    elif cmd == 'fastcgi':
        from flup.server.fcgi import WSGIServer
        error_log_path = os.path.join(app.instance_path, 'error.log')
        error_handler = logging.FileHandler(error_log_path)
        error_handler.setFormatter(log_fmt)
        error_handler.setLevel(logging.ERROR)
        logging.getLogger().addHandler(error_handler)
        sock_path = os.path.join(app.instance_path, 'fcgi.sock')
        server = WSGIServer(app, bindAddress=sock_path, umask=0)
        server.run()
开发者ID:piatra,项目名称:agenda-politicieni,代码行数:35,代码来源:agenda.py

示例2: _runFlup

# 需要导入模块: from flup.server.fcgi import WSGIServer [as 别名]
# 或者: from flup.server.fcgi.WSGIServer import run [as 别名]
def _runFlup(app, config, mode):
    """Run WsgiDAV using flup.server.fcgi, if Flup is installed."""
    try:
        # http://trac.saddi.com/flup/wiki/FlupServers
        if mode == "flup-fcgi" or "runfcgi":
            from flup.server.fcgi import WSGIServer, __version__ as flupver
        elif mode == "flup-fcgi_fork":
            from flup.server.fcgi_fork import WSGIServer, __version__ as flupver
        else:
            raise ValueError    

        if config["verbose"] >= 2:
            print "Running WsgiDAV/%s %s/%s..." % (__version__,
                                                   WSGIServer.__module__,
                                                   flupver)
        server = WSGIServer(app,
                            bindAddress=(config["host"], config["port"]),
#                            bindAddress=("127.0.0.1", 8001),
#                            debug=True,
                            )
        server.run()
    except ImportError, e:
        if config["verbose"] >= 1:
            print "Could not import flup.server.fcgi", e
        return False
开发者ID:GregoireGalland,项目名称:seafdav,代码行数:27,代码来源:run_server.py

示例3: FlupFCGIServer

# 需要导入模块: from flup.server.fcgi import WSGIServer [as 别名]
# 或者: from flup.server.fcgi.WSGIServer import run [as 别名]
class FlupFCGIServer(object):
    """Adapter for a flup.server.fcgi.WSGIServer."""
    
    def __init__(self, *args, **kwargs):
        from flup.server.fcgi import WSGIServer
        self.fcgiserver = WSGIServer(*args, **kwargs)
        # TODO: report this bug upstream to flup.
        # If we don't set _oldSIGs on Windows, we get:
        #   File "C:\Python24\Lib\site-packages\flup\server\threadedserver.py",
        #   line 108, in run
        #     self._restoreSignalHandlers()
        #   File "C:\Python24\Lib\site-packages\flup\server\threadedserver.py",
        #   line 156, in _restoreSignalHandlers
        #     for signum,handler in self._oldSIGs:
        #   AttributeError: 'WSGIServer' object has no attribute '_oldSIGs'
        self.fcgiserver._oldSIGs = []
        self.ready = False
    
    def start(self):
        """Start the FCGI server."""
        self.ready = True
        self.fcgiserver.run()
    
    def stop(self):
        """Stop the HTTP server."""
        self.ready = False
        # Forcibly stop the fcgi server main event loop.
        self.fcgiserver._keepGoing = False
        # Force all worker threads to die off.
        self.fcgiserver._threadPool.maxSpare = 0
开发者ID:fmcingvale,项目名称:cherrypy_gae,代码行数:32,代码来源:servers.py

示例4: FlupSCGIServer

# 需要导入模块: from flup.server.fcgi import WSGIServer [as 别名]
# 或者: from flup.server.fcgi.WSGIServer import run [as 别名]
class FlupSCGIServer(object):
    """Adapter for a flup.server.scgi.WSGIServer."""
    
    def __init__(self, *args, **kwargs):
        self.args = args
        self.kwargs = kwargs
        self.ready = False
    
    def start(self):
        """Start the SCGI server."""
        # We have to instantiate the server class here because its __init__
        # starts a threadpool. If we do it too early, daemonize won't work.
        from flup.server.scgi import WSGIServer
        self.scgiserver = WSGIServer(*self.args, **self.kwargs)
        # TODO: report this bug upstream to flup.
        # If we don't set _oldSIGs on Windows, we get:
        #   File "C:\Python24\Lib\site-packages\flup\server\threadedserver.py",
        #   line 108, in run
        #     self._restoreSignalHandlers()
        #   File "C:\Python24\Lib\site-packages\flup\server\threadedserver.py",
        #   line 156, in _restoreSignalHandlers
        #     for signum,handler in self._oldSIGs:
        #   AttributeError: 'WSGIServer' object has no attribute '_oldSIGs'
        self.scgiserver._installSignalHandlers = lambda: None
        self.scgiserver._oldSIGs = []
        self.ready = True
        self.scgiserver.run()
    
    def stop(self):
        """Stop the HTTP server."""
        self.ready = False
        # Forcibly stop the scgi server main event loop.
        self.scgiserver._keepGoing = False
        # Force all worker threads to die off.
        self.scgiserver._threadPool.maxSpare = 0
开发者ID:AsherBond,项目名称:DimSim,代码行数:37,代码来源:servers.py

示例5: main

# 需要导入模块: from flup.server.fcgi import WSGIServer [as 别名]
# 或者: from flup.server.fcgi.WSGIServer import run [as 别名]
def main():
    app = create_app()

    log_fmt = logging.Formatter("[%(asctime)s] %(module)s " "%(levelname)s %(message)s")

    suggestion_log_path = os.path.join(app.instance_path, "database.log")
    suggestion_handler = logging.FileHandler(suggestion_log_path)
    suggestion_handler.setFormatter(log_fmt)
    database.log.addHandler(suggestion_handler)

    import sys

    if len(sys.argv) > 1:
        cmd = sys.argv[1]
    else:
        cmd = "runserver"

    if cmd == "runserver":
        app.run(debug=True)
    elif cmd == "shell":
        from code import interact

        with app.test_request_context():
            interact(local={"app": app})
    elif cmd == "fastcgi":
        from flup.server.fcgi import WSGIServer

        error_log_path = os.path.join(app.instance_path, "error.log")
        error_handler = logging.FileHandler(error_log_path)
        error_handler.setFormatter(log_fmt)
        error_handler.setLevel(logging.ERROR)
        logging.getLogger().addHandler(error_handler)
        sock_path = os.path.join(app.instance_path, "fcgi.sock")
        server = WSGIServer(app, bindAddress=sock_path, umask=0)
        server.run()
    elif cmd == "update_identities":
        import sync

        with app.test_request_context():
            sync.update_identities()
    elif cmd == "new_people":
        with app.test_request_context():
            database.add_people(line.strip() for line in sys.stdin)
            database.db.session.commit()
开发者ID:pistruiatul,项目名称:agenda-politicieni,代码行数:46,代码来源:agenda.py

示例6: FlupFCGIServer

# 需要导入模块: from flup.server.fcgi import WSGIServer [as 别名]
# 或者: from flup.server.fcgi.WSGIServer import run [as 别名]
class FlupFCGIServer(object):
    """Adapter for a flup.server.fcgi.WSGIServer."""
    
    def __init__(self, *args, **kwargs):
        if kwargs.get('bindAddress', None) is None:
            import socket
            if not hasattr(socket.socket, 'fromfd'):
                raise ValueError(
                    'Dynamic FCGI server not available on this platform. '
                    'You must use a static or external one by providing a '
                    'legal bindAddress.')
        self.args = args
        self.kwargs = kwargs
        self.ready = False
    
    def start(self):
        """Start the FCGI server."""
        # We have to instantiate the server class here because its __init__
        # starts a threadpool. If we do it too early, daemonize won't work.
        from flup.server.fcgi import WSGIServer
        self.fcgiserver = WSGIServer(*self.args, **self.kwargs)
        # TODO: report this bug upstream to flup.
        # If we don't set _oldSIGs on Windows, we get:
        #   File "C:\Python24\Lib\site-packages\flup\server\threadedserver.py",
        #   line 108, in run
        #     self._restoreSignalHandlers()
        #   File "C:\Python24\Lib\site-packages\flup\server\threadedserver.py",
        #   line 156, in _restoreSignalHandlers
        #     for signum,handler in self._oldSIGs:
        #   AttributeError: 'WSGIServer' object has no attribute '_oldSIGs'
        self.fcgiserver._installSignalHandlers = lambda: None
        self.fcgiserver._oldSIGs = []
        self.ready = True
        self.fcgiserver.run()
    
    def stop(self):
        """Stop the HTTP server."""
        # Forcibly stop the fcgi server main event loop.
        self.fcgiserver._keepGoing = False
        # Force all worker threads to die off.
        self.fcgiserver._threadPool.maxSpare = self.fcgiserver._threadPool._idleCount
        self.ready = False
开发者ID:0-T-0,项目名称:TACTIC,代码行数:44,代码来源:servers.py

示例7: WSGIServer

# 需要导入模块: from flup.server.fcgi import WSGIServer [as 别名]
# 或者: from flup.server.fcgi.WSGIServer import run [as 别名]
#!/usr/bin/env python
import os
from flup.server.fcgi import WSGIServer
import server

wsgi = WSGIServer(server.app,
    bindAddress="/var/www/run/starroamer.sock", umask=0002)

print("running as process %s" % os.getpid())

while wsgi.run():
    reload(server)
    wsgi.application = server.app
    print("application reloaded")
开发者ID:gkrnours,项目名称:starroamer,代码行数:16,代码来源:fcgi.py

示例8: WSGIServer

# 需要导入模块: from flup.server.fcgi import WSGIServer [as 别名]
# 或者: from flup.server.fcgi.WSGIServer import run [as 别名]
from flup.server.fcgi import WSGIServer
from weeklypedia.labs import wsgi_app


wsgi_server = WSGIServer(wsgi_app)


if __name__ == "__main__":
    wsgi_server.run()
开发者ID:jrbsu,项目名称:weeklypedia,代码行数:11,代码来源:run_labs_fcgi.py

示例9: LinkRecommender

# 需要导入模块: from flup.server.fcgi import WSGIServer [as 别名]
# 或者: from flup.server.fcgi.WSGIServer import run [as 别名]
    # testLang = u"en";

    # testItems = {
    #     u"Luis Hernández": 1,
    #     u"Mexikói labdarúgó-válogatott": 1,
    #     u"Labdarúgó": 1,
    #     u"CA Boca Juniors": 1,
    #     u"CF Monterrey": 1
    #     }
    # testLang = u"hu";

    # testItems = {
    #     u"باشگاه فوتبال بوکا جونیورز": 1,
    #     u"فوتبال": 1,
    #     u"زبان اسپانیایی": 1,
    #     u"آرژانتین": 1};
    # testLang = u"fa";
   
    # logging.basicConfig(level=logging.DEBUG)

    # recommender = LinkRecommender(lang=testLang, nrecs=2500, verbose=True);
    # recommender.connect();
    # recs = recommender.get_recs(item_map=testItems, \
    #                                 param_map=dict({u'nrecs': 2500,u'lang': testLang}));
    # recommender.close();
    # print "Received %d recommendations." % (len(recs),);

# Also, comment out these if you run from command line
wsgi = WSGIServer(app);
wsgi.run();
开发者ID:stuem007,项目名称:suggestbot,代码行数:32,代码来源:link-recommender.py

示例10: handle

# 需要导入模块: from flup.server.fcgi import WSGIServer [as 别名]
# 或者: from flup.server.fcgi.WSGIServer import run [as 别名]
 def handle(self, app):
     _error_log(os.path.join(app.instance_path, 'error.log'))
     from flup.server.fcgi import WSGIServer
     sock_path = os.path.join(app.instance_path, 'fcgi.sock')
     server = WSGIServer(app, bindAddress=sock_path, umask=0)
     server.run()
开发者ID:mgax,项目名称:Lawn,代码行数:8,代码来源:lawn.py

示例11: handle

# 需要导入模块: from flup.server.fcgi import WSGIServer [as 别名]
# 或者: from flup.server.fcgi.WSGIServer import run [as 别名]
 def handle(self, app, sock):
     _production_logging(app)
     from flup.server.fcgi import WSGIServer
     server = WSGIServer(app, bindAddress=sock, umask=0, maxThreads=5)
     server.run()
开发者ID:pombredanne,项目名称:cites-meetings,代码行数:7,代码来源:manage.py

示例12: open

# 需要导入模块: from flup.server.fcgi import WSGIServer [as 别名]
# 或者: from flup.server.fcgi.WSGIServer import run [as 别名]
#!/usr/bin/python
"""
FastCGI server using flup. Reloads on SIGHUP.
"""
import site, os
site.addsitedir(os.path.dirname(__file__))
import restrack.server
from flup.server.fcgi import WSGIServer
import os, sys, logging, site

lh = logging.StreamHandler(sys.stderr)
lh.setFormatter(logging.Formatter(restrack.server.FORMAT))
logging.root.addHandler(lh)
logging.root.setLevel(logging.DEBUG)

f = open('/tmp/restracker.pid', 'w')
f.write(str(os.getpid()))
f.close()

try:
	ws = WSGIServer(restrack.server.restracker_app, bindAddress='/tmp/restracker.sock')
	rerun = ws.run()
finally:
	os.unlink('/tmp/restracker.pid')

if rerun:
	os.spawnv(__file__, sys.argv)

开发者ID:astronouth7303,项目名称:restracker,代码行数:29,代码来源:fastcgi-server.py

示例13: run_fcgi

# 需要导入模块: from flup.server.fcgi import WSGIServer [as 别名]
# 或者: from flup.server.fcgi.WSGIServer import run [as 别名]
def run_fcgi(app, args):
    from flup.server.fcgi import WSGIServer
    sock_path = args.fastcgi_socket
    wsgi_server = WSGIServer(app, bindAddress=sock_path, umask=0)
    wsgi_server.run()
开发者ID:mgax,项目名称:civic-site,代码行数:7,代码来源:civic_site.py

示例14: handle

# 需要导入模块: from flup.server.fcgi import WSGIServer [as 别名]
# 或者: from flup.server.fcgi.WSGIServer import run [as 别名]
 def handle(self, app):
     _production_logging(app)
     from flup.server.fcgi import WSGIServer
     sock_path = os.path.join(app.instance_path, 'fcgi.sock')
     server = WSGIServer(app, bindAddress=sock_path, umask=0)
     server.run()
开发者ID:dincamihai,项目名称:cites-meetings,代码行数:8,代码来源:manage.py

示例15: run

# 需要导入模块: from flup.server.fcgi import WSGIServer [as 别名]
# 或者: from flup.server.fcgi.WSGIServer import run [as 别名]
def run( app=None, components=(), method=STANDALONE, name="retro",
root = ".", resetlog=False, address="", port=None, prefix='', asynchronous=False,
sessions=False, withReactor=None, processStack=lambda x:x, runCondition=lambda:True,
onError=None ):
	"""Runs this web application with the given method (easiest one is STANDALONE),
	with the given root (directory from where the web app-related resource
	will be resolved).

	This function is the 'main' for your web application, so this is basically
	the last call you should have in your web application main."""
	if app == None:
		app = Application(prefix=prefix,components=components)
	else:
		for _ in components: app.register(_)
	# We set up the configuration if necessary
	config = app.config()
	if not config: config = Configuration(CONFIG)
	# Adjusts the working directory to basepath
	root = os.path.abspath(root)
	if os.path.isfile(root): root = os.path.dirname(root)
	# We set the application root to the given root, and do a chdir
	os.chdir(root)
	config.setdefault("root",    root)
	config.setdefault("name",    name)
	config.setdefault("logfile", name + ".log")
	if resetlog: os.path.unlink(config.logfile())
	# We set the configuration
	app.config(config)
	# And start the application
	app.start()
	# NOTE: Maybe we should always print it
	#print app.config()
	# We start the WSGI stack
	stack = app._dispatcher
	stack = processStack(stack)
	# == FCGI (Flup-provided)
	#
	if method == FCGI:
		if not has(FLUP):
			raise ImportError("Flup is required to run FCGI")
		fcgi_address = address or config.get("address")
		fcgi_port    = port or config.get("port")
		if fcgi_port and fcgi_address:
			server = FLUP_FCGIServer(stack, bindAddress=(fcgi_address, fcgi_port))
		elif fcgi_address:
			server = FLUP_FCGIServer(stack, bindAddress=fcgi_address)
		else:
			server = FLUP_FCGIServer(stack)
		server.run()
	#
	# == SCGI (Flup-provided)
	#
	elif method == SCGI:
		if not has(FLUP):
			raise ImportError("Flup is required to run SCGI")
		fcgi_address = address or config.get("address")
		fcgi_port    = port or config.get("port")
		if fcgi_port and fcgi_address:
			server = FLUP_SCGIServer(stack, bindAddress=(fcgi_address, fcgi_port))
		elif fcgi_address:
			server = FLUP_SCGIServer(stack, bindAddress=fcgi_address)
		else:
			server = FLUP_SCGIServer(stack)
		server.run()
	#
	# == CGI
	#
	elif method == CGI:
		environ         = {} ; environ.update(os.environ)
		# From <http://www.python.org/dev/peps/pep-0333/#the-server-gateway-side>
		environ['wsgi.input']        = sys.stdin
		environ['wsgi.errors']       = sys.stderr
		environ['wsgi.version']      = (1,0)
		environ['wsgi.multithread']  = False
		environ['wsgi.multiprocess'] = True
		environ['wsgi.run_once']     = True
		if environ.get('HTTPS','off') in ('on','1'):
			environ['wsgi.url_scheme'] = 'https'
		else:
			environ['wsgi.url_scheme'] = 'http'
		# FIXME: Don't know if it's the proper solution
		req_uri = environ["REQUEST_URI"]
		script_name = environ["SCRIPT_NAME"]
		if req_uri.startswith(script_name):
			environ["PATH_INFO"]  = req_uri[len(script_name):]
		else:
			environ["PATH_INFO"]  = "/"
		if sessions:
			environ["com.saddi.service.session"] = sessions
		def start_response( status, headers, executionInfo=None ):
			for key, value in headers:
				print ("%s: %s" % (key, value))
			print ()
		# FIXME: This is broken
		res = "".join(tuple(self.dispatcher(environ, start_response)))
		print (res)
		if sessions:
			sessions.close()
	#
	# == GEVENT, BJOERN, ROCKET & WSGI
#.........这里部分代码省略.........
开发者ID:sebastien,项目名称:retro,代码行数:103,代码来源:__init__.py


注:本文中的flup.server.fcgi.WSGIServer.run方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。