def bind_server_socket(self): cleanup_unix_socket(self.adj.unix_socket) self.bind(self.adj.unix_socket) if os.path.exists(self.adj.unix_socket): os.chmod(self.adj.unix_socket, self.adj.unix_socket_perms)
def create_server(application, ssl=None, **adj): """Create a wsgi server: .. code-block:: >>> @asyncio.coroutine ... def application(environ, start_response): ... pass >>> loop = asyncio.get_event_loop() >>> srv = create_server(application, loop=loop, port=2345) >>> srv.close() Then use ``srv.run()`` or ``loop.run_forever()`` """ if 'loop' in adj: loop = adj.pop('loop') else: loop = asyncio.get_event_loop() if 'ident' not in adj: adj['ident'] = 'aiowsgi' server = waitress.create_server(application, _start=False, **adj) adj = server.adj server.executor = None if not asyncio.iscoroutine(application) and \ not asyncio.iscoroutinefunction(application): server.executor = ThreadPoolExecutor(max_workers=adj.threads) server.run = loop.run_forever server.loop = loop args = dict(app=[application], aioserver=None, adj=adj, loop=loop, server=server, server_name=server.server_name, effective_host=server.effective_host, effective_port=server.effective_port) proto = type(str('BoundedWSGIProtocol'), (WSGIProtocol, ), args) server.proto = proto if adj.unix_socket: utilities.cleanup_unix_socket(adj.unix_socket) f = loop.create_unix_server else: f = loop.create_server def done(future): result = future.result() server.aioserver = result task = asyncio.ensure_future(f(proto, sock=server.socket, backlog=adj.backlog, ssl=ssl), loop=loop) task.add_done_callback(done) return server