當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。