當前位置: 首頁>>代碼示例>>Python>>正文


Python gevent.server方法代碼示例

本文整理匯總了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) 
開發者ID:fake-name,項目名稱:ReadableWebProxy,代碼行數:22,代碼來源:server.py

示例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', '') 
開發者ID:leancloud,項目名稱:satori,代碼行數:22,代碼來源:pywsgi.py

示例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 
開發者ID:NASA-AMMOS,項目名稱:AIT-Core,代碼行數:22,代碼來源:api.py

示例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 
開發者ID:dongweiming,項目名稱:web_develop,代碼行數:25,代碼來源:portforwarder.py

示例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() 
開發者ID:simplecrypto,項目名稱:powerpool,代碼行數:19,代碼來源:main.py

示例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', '') 
開發者ID:priyankark,項目名稱:PhonePi_SampleServer,代碼行數:22,代碼來源:pywsgi.py

示例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() 
開發者ID:priyankark,項目名稱:PhonePi_SampleServer,代碼行數:25,代碼來源:pywsgi.py

示例8: server

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import server [as 別名]
def server():
    ss = StreamServer(('localhost', PORT), serve).serve_forever() 
開發者ID:jgehrcke,項目名稱:gipc,代碼行數:4,代碼來源:serverclient.py

示例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) 
開發者ID:jpush,項目名稱:jbox,代碼行數:13,代碼來源:ggevent.py

示例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 
開發者ID:fake-name,項目名稱:ReadableWebProxy,代碼行數:16,代碼來源:server.py

示例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() 
開發者ID:fake-name,項目名稱:ReadableWebProxy,代碼行數:6,代碼來源:server.py

示例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() 
開發者ID:fake-name,項目名稱:ReadableWebProxy,代碼行數:9,代碼來源:server.py

示例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 
開發者ID:leancloud,項目名稱:satori,代碼行數:15,代碼來源:pywsgi.py

示例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() 
開發者ID:leancloud,項目名稱:satori,代碼行數:17,代碼來源:pywsgi.py

示例15: log_request

# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import server [as 別名]
def log_request(self):
        self.server.log.write(self.format_request() + '\n') 
開發者ID:leancloud,項目名稱:satori,代碼行數:4,代碼來源:pywsgi.py


注:本文中的gevent.server方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。