本文整理汇总了Python中flup.server.fcgi.WSGIServer类的典型用法代码示例。如果您正苦于以下问题:Python WSGIServer类的具体用法?Python WSGIServer怎么用?Python WSGIServer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了WSGIServer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: FlupFCGIServer
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
示例2: _runFlup
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
示例3: main
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()
示例4: FlupSCGIServer
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
示例5: main
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()
示例6: FlupFCGIServer
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
示例7: __init__
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
示例8: start
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()
示例9: WSGIServer
from flup.server.fcgi import WSGIServer
from weeklypedia.labs import wsgi_app
wsgi_server = WSGIServer(wsgi_app)
if __name__ == "__main__":
wsgi_server.run()
示例10: LinkRecommender
# 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();
示例11: _mainloopPeriodic
def _mainloopPeriodic(self):
WSGIServer._mainloopPeriodic(self)
if getmtime(__file__) != START_TIME:
self._keepGoing = False
示例12: handle
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()
示例13: open
#!/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)
示例14: run_fcgi
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()
示例15: handle
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()