本文整理汇总了Python中gevent.server方法的典型用法代码示例。如果您正苦于以下问题:Python gevent.server方法的具体用法?Python gevent.server怎么用?Python gevent.server使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gevent
的用法示例。
在下文中一共展示了gevent.server方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import server [as 别名]
def main():
print("Preloading cache directories")
# print("Testing reload")
# server.tree.tree.reloadTree()
# print("Starting RPC server")
try:
run()
except:
# abort /hard/ if we exceptioned out of the main run.
# This should (hopeully) cause the OS to terminate any
# remaining threads.
# As it is, I've been having issues with the main thread failing
# with 'OSError: [Errno 24] Too many open files', killing the main thread
# and leaving some of the amqp interface threads dangling.
# Somehow, it's not being caught in the `except Exception:` handler
# in run(). NFI how.
import ctypes
ctypes.string_at(0)
示例2: update_environ
# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import server [as 别名]
def update_environ(self):
"""
Called before the first request is handled to fill in WSGI environment values.
This includes getting the correct server name and port.
"""
address = self.address
if isinstance(address, tuple):
if 'SERVER_NAME' not in self.environ:
try:
name = socket.getfqdn(address[0])
except socket.error:
name = str(address[0])
if PY3 and not isinstance(name, str):
name = name.decode('ascii')
self.environ['SERVER_NAME'] = name
self.environ.setdefault('SERVER_PORT', str(address[1]))
else:
self.environ.setdefault('SERVER_NAME', '')
self.environ.setdefault('SERVER_PORT', '')
示例3: __init__
# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import server [as 别名]
def __init__ (self, listener, pktbuf, defn=None):
"""Creates a new UdpTelemetryServer.
The server listens for UDP packets matching the given
``PacketDefinition`` *defn*.
The *listener* is either a port on localhost, a tuple
containing ``(hostname, port)``, or a
``gevent.socket.socket``.
If the optional *defn* is not specified, the first
``PacketDefinition`` (alphabetical by name) in the default
telemetry dictionary (i.e. ``tlm.getDefaultDict()``) is used.
"""
if type(listener) is int:
listener = ('127.0.0.1', listener)
super(UdpTelemetryServer, self).__init__(listener)
self._defn = defn
self._pktbuf = pktbuf
示例4: forward
# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import server [as 别名]
def forward(source, dest, server):
source_address = '%s:%s' % source.getpeername()[:2]
dest_address = '%s:%s' % dest.getpeername()[:2]
try:
while True:
try:
data = source.recv(1024)
log('%s->%s', source_address, dest_address)
if not data:
break
dest.sendall(data)
except KeyboardInterrupt:
if not server.closed:
server.close()
break
except socket.error:
if not server.closed:
server.close()
break
finally:
source.close()
dest.close()
server = None
示例5: main
# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import server [as 别名]
def main():
parser = argparse.ArgumentParser(description='Run powerpool!')
parser.add_argument('config', type=argparse.FileType('r'),
help='yaml configuration file to run with')
parser.add_argument('-d', '--dump-config', action="store_true",
help='print the result of the YAML configuration file and exit')
parser.add_argument('-s', '--server-number', type=int, default=0,
help='increase the configued server_number by this much')
args = parser.parse_args()
# override those defaults with a loaded yaml config
raw_config = yaml.load(args.config) or {}
if args.dump_config:
import pprint
pprint.pprint(raw_config)
exit(0)
PowerPool.from_raw_config(raw_config, vars(args)).start()
示例6: update_environ
# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import server [as 别名]
def update_environ(self):
"""
Called before the first request is handled to fill in WSGI environment values.
This includes getting the correct server name and port.
"""
address = self.address
if isinstance(address, tuple):
if 'SERVER_NAME' not in self.environ:
try:
name = socket.getfqdn(address[0])
except socket.error:
name = str(address[0])
if PY3 and not isinstance(name, str):
name = name.decode('ascii') # python 2 pylint:disable=redefined-variable-type
self.environ['SERVER_NAME'] = name
self.environ.setdefault('SERVER_PORT', str(address[1]))
else:
self.environ.setdefault('SERVER_NAME', '')
self.environ.setdefault('SERVER_PORT', '')
示例7: _main
# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import server [as 别名]
def _main():
# Provisional main handler, for quick tests, not production
# usage.
from gevent import monkey; monkey.patch_all()
import argparse
import importlib
parser = argparse.ArgumentParser()
parser.add_argument("app", help="dotted name of WSGI app callable [module:callable]")
parser.add_argument("-b", "--bind",
help="The socket to bind",
default=":8080")
args = parser.parse_args()
module_name, app_name = args.app.split(':')
module = importlib.import_module(module_name)
app = getattr(module, app_name)
bind = args.bind
server = WSGIServer(bind, app)
server.serve_forever()
示例8: server
# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import server [as 别名]
def server():
ss = StreamServer(('localhost', PORT), serve).serve_forever()
示例9: log_request
# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import server [as 别名]
def log_request(self):
start = datetime.fromtimestamp(self.time_start)
finish = datetime.fromtimestamp(self.time_finish)
response_time = finish - start
resp_headers = getattr(self, 'response_headers', {})
resp = GeventResponse(self.status, resp_headers, self.response_length)
if hasattr(self, 'headers'):
req_headers = [h.split(":", 1) for h in self.headers.headers]
else:
req_headers = []
self.server.log.access(resp, req_headers, self.environ, response_time)
示例10: build_mprpc_handler
# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import server [as 别名]
def build_mprpc_handler(server):
global TO_EXIT
TO_EXIT.append(server)
def handler(signum=-1, frame=None):
global INTERRUPTS
INTERRUPTS += 1
print('Signal handler called with signal %s for the %s time' % (signum, INTERRUPTS))
if INTERRUPTS > 2:
print("Raising due to repeat interrupts")
raise KeyboardInterrupt
for server in TO_EXIT:
server.close()
return handler
示例11: base_abort
# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import server [as 别名]
def base_abort():
print("Low level keyboard interrupt")
for server in TO_EXIT:
server.close()
示例12: run_rpc
# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import server [as 别名]
def run_rpc(interface_dict):
print("MpRPC server Started.")
server_instance = FetchInterfaceClass(interface_dict, "MpRPC")
mprpc_server = StreamServer(('0.0.0.0', 4315), server_instance)
gevent.signal(signal.SIGINT, build_mprpc_handler(mprpc_server))
mprpc_server.serve_forever()
示例13: __init__
# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import server [as 别名]
def __init__(self, socket, address, server, rfile=None):
# Deprecation: The rfile kwarg was introduced in 1.0a1 as part
# of a refactoring. It was never documented or used. It is
# considered DEPRECATED and may be removed in the future. Its
# use is not supported.
self.socket = socket
self.client_address = address
self.server = server
if rfile is None:
self.rfile = socket.makefile('rb', -1)
else:
self.rfile = rfile
示例14: log_error
# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import server [as 别名]
def log_error(self, msg, *args):
try:
message = msg % args
except Exception:
traceback.print_exc()
message = '%r %r' % (msg, args)
try:
message = '%s: %s' % (self.socket, message)
except Exception:
pass
try:
self.server.error_log.write(message + '\n')
except Exception:
traceback.print_exc()
示例15: log_request
# 需要导入模块: import gevent [as 别名]
# 或者: from gevent import server [as 别名]
def log_request(self):
self.server.log.write(self.format_request() + '\n')