We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Recent change to GunicornWebWorker breaks code
## Long story short

For development, I like using the autoreload feature you can get with gunicorn; so I've been using the following python script to start up a development server:

``` python
import os

if __name__ == '__main__':
    command = (
        'gunicorn server:app ' +
        '--bind 0.0.0.0:5000 ' +
        '--workers 1 ' +
        '--worker-class aiohttp.worker.GunicornUVLoopWebWorker ' +
        '--reload')
    os.system(command)
```

This works on the 0.22 branch, but fails when I move to the master branch (1.0.0a0).  I get the following traceback using the master branch when I try to launch the server:

```
Traceback (most recent call last):
  File "/Users/bcmyers/Dropbox/Programming/python/website/venv/lib/python3.5/site-packages/gunicorn/arbiter.py", line 557, in spawn_worker
    worker.init_process()
  File "/Users/bcmyers/Dropbox/Programming/python/website/venv/lib/python3.5/site-packages/aiohttp/worker.py", line 196, in init_process
    super().init_process()
  File "/Users/bcmyers/Dropbox/Programming/python/website/venv/lib/python3.5/site-packages/aiohttp/worker.py", line 36, in init_process
    super().init_process()
  File "/Users/bcmyers/Dropbox/Programming/python/website/venv/lib/python3.5/site-packages/gunicorn/workers/base.py", line 132, in init_process
    self.run()
  File "/Users/bcmyers/Dropbox/Programming/python/website/venv/lib/python3.5/site-packages/aiohttp/worker.py", line 43, in run
    self.loop.run_until_complete(self._runner)
  File "uvloop/loop.pyx", line 1133, in uvloop.loop.Loop.run_until_complete (uvloop/loop.c:19943)
  File "uvloop/future.pyx", line 123, in uvloop.loop.BaseFuture.result (uvloop/loop.c:94147)
  File "uvloop/future.pyx", line 78, in uvloop.loop.BaseFuture._result_impl (uvloop/loop.c:93686)
  File "uvloop/task.pyx", line 126, in uvloop.loop.BaseTask._fast_step (uvloop/loop.c:99430)
  File "/Users/bcmyers/Dropbox/Programming/python/website/venv/lib/python3.5/site-packages/aiohttp/worker.py", line 91, in _run
    handler = self.make_handler(self.wsgi)
  File "/Users/bcmyers/Dropbox/Programming/python/website/venv/lib/python3.5/site-packages/aiohttp/worker.py", line 52, in make_handler
    debug=self.cfg.debug,
  File "/Users/bcmyers/Dropbox/Programming/python/website/venv/lib/python3.5/site-packages/gunicorn/config.py", line 58, in __getattr__
    raise AttributeError("No configuration setting for: %s" % name)
AttributeError: No configuration setting for: debug
```

I think the reason is that the `make_handler` method on the `GunicornWebWorker` class has changed from this:

``` python
def make_handler(self, app):
    if hasattr(self.cfg, 'debug'):
        is_debug = self.cfg.debug
    else:
        is_debug = self.log.loglevel == logging.DEBUG

    return app.make_handler(
        logger=self.log,
        debug=is_debug,
        timeout=self.cfg.timeout,
        keep_alive=self.cfg.keepalive,
        access_log=self.log.access_log,
        access_log_format=self.cfg.access_log_format)
```

to this:

``` python
def make_handler(self, app):
    return app.make_handler(
        logger=self.log,
        debug=self.cfg.debug,
        timeout=self.cfg.timeout,
        keep_alive=self.cfg.keepalive,
        access_log=self.log.access_log,
        access_log_format=self._get_valid_log_format(
            self.cfg.access_log_format))
```

It appears my `cfg` object has no `debug` attribute, which was fine on branch 0.22 but leads to my script failing on the master branch.  Is this a bug?  If not, it would be great if someone could let me know how to fix my code.

Thanks!
## My environment

```
aiohttp==1.0.0a0
gunicorn==19.6.0
uvloop==0.5.3
```


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `aiohttp/worker.py`
Content:
```
1 """Async gunicorn worker for aiohttp.web"""
2 
3 import asyncio
4 import os
5 import re
6 import signal
7 import ssl
8 import sys
9 
10 import gunicorn.workers.base as base
11 from gunicorn.config import AccessLogFormat as GunicornAccessLogFormat
12 
13 from aiohttp.helpers import AccessLogger, ensure_future
14 
15 __all__ = ('GunicornWebWorker', 'GunicornUVLoopWebWorker')
16 
17 
18 class GunicornWebWorker(base.Worker):
19 
20     DEFAULT_AIOHTTP_LOG_FORMAT = AccessLogger.LOG_FORMAT
21     DEFAULT_GUNICORN_LOG_FORMAT = GunicornAccessLogFormat.default
22 
23     def __init__(self, *args, **kw):  # pragma: no cover
24         super().__init__(*args, **kw)
25 
26         self.servers = {}
27         self.exit_code = 0
28 
29     def init_process(self):
30         # create new event_loop after fork
31         asyncio.get_event_loop().close()
32 
33         self.loop = asyncio.new_event_loop()
34         asyncio.set_event_loop(self.loop)
35 
36         super().init_process()
37 
38     def run(self):
39         self.loop.run_until_complete(self.wsgi.startup())
40         self._runner = ensure_future(self._run(), loop=self.loop)
41 
42         try:
43             self.loop.run_until_complete(self._runner)
44         finally:
45             self.loop.close()
46 
47         sys.exit(self.exit_code)
48 
49     def make_handler(self, app):
50         return app.make_handler(
51             logger=self.log,
52             debug=self.cfg.debug,
53             timeout=self.cfg.timeout,
54             keep_alive=self.cfg.keepalive,
55             access_log=self.log.access_log,
56             access_log_format=self._get_valid_log_format(
57                 self.cfg.access_log_format))
58 
59     @asyncio.coroutine
60     def close(self):
61         if self.servers:
62             servers = self.servers
63             self.servers = None
64 
65             # stop accepting connections
66             for server, handler in servers.items():
67                 self.log.info("Stopping server: %s, connections: %s",
68                               self.pid, len(handler.connections))
69                 server.close()
70                 yield from server.wait_closed()
71 
72             # send on_shutdown event
73             yield from self.wsgi.shutdown()
74 
75             # stop alive connections
76             tasks = [
77                 handler.finish_connections(
78                     timeout=self.cfg.graceful_timeout / 100 * 95)
79                 for handler in servers.values()]
80             yield from asyncio.gather(*tasks, loop=self.loop)
81 
82             # cleanup application
83             yield from self.wsgi.cleanup()
84 
85     @asyncio.coroutine
86     def _run(self):
87 
88         ctx = self._create_ssl_context(self.cfg) if self.cfg.is_ssl else None
89 
90         for sock in self.sockets:
91             handler = self.make_handler(self.wsgi)
92             srv = yield from self.loop.create_server(handler, sock=sock.sock,
93                                                      ssl=ctx)
94             self.servers[srv] = handler
95 
96         # If our parent changed then we shut down.
97         pid = os.getpid()
98         try:
99             while self.alive:
100                 self.notify()
101 
102                 cnt = sum(handler.requests_count
103                           for handler in self.servers.values())
104                 if self.cfg.max_requests and cnt > self.cfg.max_requests:
105                     self.alive = False
106                     self.log.info("Max requests, shutting down: %s", self)
107 
108                 elif pid == os.getpid() and self.ppid != os.getppid():
109                     self.alive = False
110                     self.log.info("Parent changed, shutting down: %s", self)
111                 else:
112                     yield from asyncio.sleep(1.0, loop=self.loop)
113 
114         except BaseException:
115             pass
116 
117         yield from self.close()
118 
119     def init_signals(self):
120         # Set up signals through the event loop API.
121 
122         self.loop.add_signal_handler(signal.SIGQUIT, self.handle_quit,
123                                      signal.SIGQUIT, None)
124 
125         self.loop.add_signal_handler(signal.SIGTERM, self.handle_exit,
126                                      signal.SIGTERM, None)
127 
128         self.loop.add_signal_handler(signal.SIGINT, self.handle_quit,
129                                      signal.SIGINT, None)
130 
131         self.loop.add_signal_handler(signal.SIGWINCH, self.handle_winch,
132                                      signal.SIGWINCH, None)
133 
134         self.loop.add_signal_handler(signal.SIGUSR1, self.handle_usr1,
135                                      signal.SIGUSR1, None)
136 
137         self.loop.add_signal_handler(signal.SIGABRT, self.handle_abort,
138                                      signal.SIGABRT, None)
139 
140         # Don't let SIGTERM and SIGUSR1 disturb active requests
141         # by interrupting system calls
142         signal.siginterrupt(signal.SIGTERM, False)
143         signal.siginterrupt(signal.SIGUSR1, False)
144 
145     def handle_quit(self, sig, frame):
146         self.alive = False
147 
148     def handle_abort(self, sig, frame):
149         self.alive = False
150         self.exit_code = 1
151 
152     @staticmethod
153     def _create_ssl_context(cfg):
154         """ Creates SSLContext instance for usage in asyncio.create_server.
155 
156         See ssl.SSLSocket.__init__ for more details.
157         """
158         ctx = ssl.SSLContext(cfg.ssl_version)
159         ctx.load_cert_chain(cfg.certfile, cfg.keyfile)
160         ctx.verify_mode = cfg.cert_reqs
161         if cfg.ca_certs:
162             ctx.load_verify_locations(cfg.ca_certs)
163         if cfg.ciphers:
164             ctx.set_ciphers(cfg.ciphers)
165         return ctx
166 
167     def _get_valid_log_format(self, source_format):
168         if source_format == self.DEFAULT_GUNICORN_LOG_FORMAT:
169             return self.DEFAULT_AIOHTTP_LOG_FORMAT
170         elif re.search(r'%\([^\)]+\)', source_format):
171             raise ValueError(
172                 "Gunicorn's style options in form of `%(name)s` are not "
173                 "supported for the log formatting. Please use aiohttp's "
174                 "format specification to configure access log formatting: "
175                 "http://aiohttp.readthedocs.io/en/stable/logging.html"
176                 "#format-specification"
177             )
178         else:
179             return source_format
180 
181 
182 class GunicornUVLoopWebWorker(GunicornWebWorker):
183 
184     def init_process(self):
185         import uvloop
186 
187         # Close any existing event loop before setting a
188         # new policy.
189         asyncio.get_event_loop().close()
190 
191         # Setup uvloop policy, so that every
192         # asyncio.get_event_loop() will create an instance
193         # of uvloop event loop.
194         asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
195 
196         super().init_process()
197
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/aiohttp/worker.py b/aiohttp/worker.py
--- a/aiohttp/worker.py
+++ b/aiohttp/worker.py
@@ -1,6 +1,7 @@
 """Async gunicorn worker for aiohttp.web"""
 
 import asyncio
+import logging
 import os
 import re
 import signal
@@ -47,11 +48,16 @@
         sys.exit(self.exit_code)
 
     def make_handler(self, app):
+        if hasattr(self.cfg, 'debug'):
+            is_debug = self.cfg.debug
+        else:
+            is_debug = self.log.loglevel == logging.DEBUG
+
         return app.make_handler(
             logger=self.log,
-            debug=self.cfg.debug,
-            timeout=self.cfg.timeout,
-            keep_alive=self.cfg.keepalive,
+            debug=is_debug,
+            slow_request_timeout=self.cfg.timeout,
+            keepalive_timeout=self.cfg.keepalive,
             access_log=self.log.access_log,
             access_log_format=self._get_valid_log_format(
                 self.cfg.access_log_format))

{"golden_diff": "diff --git a/aiohttp/worker.py b/aiohttp/worker.py\n--- a/aiohttp/worker.py\n+++ b/aiohttp/worker.py\n@@ -1,6 +1,7 @@\n \"\"\"Async gunicorn worker for aiohttp.web\"\"\"\n \n import asyncio\n+import logging\n import os\n import re\n import signal\n@@ -47,11 +48,16 @@\n         sys.exit(self.exit_code)\n \n     def make_handler(self, app):\n+        if hasattr(self.cfg, 'debug'):\n+            is_debug = self.cfg.debug\n+        else:\n+            is_debug = self.log.loglevel == logging.DEBUG\n+\n         return app.make_handler(\n             logger=self.log,\n-            debug=self.cfg.debug,\n-            timeout=self.cfg.timeout,\n-            keep_alive=self.cfg.keepalive,\n+            debug=is_debug,\n+            slow_request_timeout=self.cfg.timeout,\n+            keepalive_timeout=self.cfg.keepalive,\n             access_log=self.log.access_log,\n             access_log_format=self._get_valid_log_format(\n                 self.cfg.access_log_format))\n", "issue": "Recent change to GunicornWebWorker breaks code\n## Long story short\n\nFor development, I like using the autoreload feature you can get with gunicorn; so I've been using the following python script to start up a development server:\n\n``` python\nimport os\n\nif __name__ == '__main__':\n    command = (\n        'gunicorn server:app ' +\n        '--bind 0.0.0.0:5000 ' +\n        '--workers 1 ' +\n        '--worker-class aiohttp.worker.GunicornUVLoopWebWorker ' +\n        '--reload')\n    os.system(command)\n```\n\nThis works on the 0.22 branch, but fails when I move to the master branch (1.0.0a0).  I get the following traceback using the master branch when I try to launch the server:\n\n```\nTraceback (most recent call last):\n  File \"/Users/bcmyers/Dropbox/Programming/python/website/venv/lib/python3.5/site-packages/gunicorn/arbiter.py\", line 557, in spawn_worker\n    worker.init_process()\n  File \"/Users/bcmyers/Dropbox/Programming/python/website/venv/lib/python3.5/site-packages/aiohttp/worker.py\", line 196, in init_process\n    super().init_process()\n  File \"/Users/bcmyers/Dropbox/Programming/python/website/venv/lib/python3.5/site-packages/aiohttp/worker.py\", line 36, in init_process\n    super().init_process()\n  File \"/Users/bcmyers/Dropbox/Programming/python/website/venv/lib/python3.5/site-packages/gunicorn/workers/base.py\", line 132, in init_process\n    self.run()\n  File \"/Users/bcmyers/Dropbox/Programming/python/website/venv/lib/python3.5/site-packages/aiohttp/worker.py\", line 43, in run\n    self.loop.run_until_complete(self._runner)\n  File \"uvloop/loop.pyx\", line 1133, in uvloop.loop.Loop.run_until_complete (uvloop/loop.c:19943)\n  File \"uvloop/future.pyx\", line 123, in uvloop.loop.BaseFuture.result (uvloop/loop.c:94147)\n  File \"uvloop/future.pyx\", line 78, in uvloop.loop.BaseFuture._result_impl (uvloop/loop.c:93686)\n  File \"uvloop/task.pyx\", line 126, in uvloop.loop.BaseTask._fast_step (uvloop/loop.c:99430)\n  File \"/Users/bcmyers/Dropbox/Programming/python/website/venv/lib/python3.5/site-packages/aiohttp/worker.py\", line 91, in _run\n    handler = self.make_handler(self.wsgi)\n  File \"/Users/bcmyers/Dropbox/Programming/python/website/venv/lib/python3.5/site-packages/aiohttp/worker.py\", line 52, in make_handler\n    debug=self.cfg.debug,\n  File \"/Users/bcmyers/Dropbox/Programming/python/website/venv/lib/python3.5/site-packages/gunicorn/config.py\", line 58, in __getattr__\n    raise AttributeError(\"No configuration setting for: %s\" % name)\nAttributeError: No configuration setting for: debug\n```\n\nI think the reason is that the `make_handler` method on the `GunicornWebWorker` class has changed from this:\n\n``` python\ndef make_handler(self, app):\n    if hasattr(self.cfg, 'debug'):\n        is_debug = self.cfg.debug\n    else:\n        is_debug = self.log.loglevel == logging.DEBUG\n\n    return app.make_handler(\n        logger=self.log,\n        debug=is_debug,\n        timeout=self.cfg.timeout,\n        keep_alive=self.cfg.keepalive,\n        access_log=self.log.access_log,\n        access_log_format=self.cfg.access_log_format)\n```\n\nto this:\n\n``` python\ndef make_handler(self, app):\n    return app.make_handler(\n        logger=self.log,\n        debug=self.cfg.debug,\n        timeout=self.cfg.timeout,\n        keep_alive=self.cfg.keepalive,\n        access_log=self.log.access_log,\n        access_log_format=self._get_valid_log_format(\n            self.cfg.access_log_format))\n```\n\nIt appears my `cfg` object has no `debug` attribute, which was fine on branch 0.22 but leads to my script failing on the master branch.  Is this a bug?  If not, it would be great if someone could let me know how to fix my code.\n\nThanks!\n## My environment\n\n```\naiohttp==1.0.0a0\ngunicorn==19.6.0\nuvloop==0.5.3\n```\n\n", "before_files": [{"content": "\"\"\"Async gunicorn worker for aiohttp.web\"\"\"\n\nimport asyncio\nimport os\nimport re\nimport signal\nimport ssl\nimport sys\n\nimport gunicorn.workers.base as base\nfrom gunicorn.config import AccessLogFormat as GunicornAccessLogFormat\n\nfrom aiohttp.helpers import AccessLogger, ensure_future\n\n__all__ = ('GunicornWebWorker', 'GunicornUVLoopWebWorker')\n\n\nclass GunicornWebWorker(base.Worker):\n\n    DEFAULT_AIOHTTP_LOG_FORMAT = AccessLogger.LOG_FORMAT\n    DEFAULT_GUNICORN_LOG_FORMAT = GunicornAccessLogFormat.default\n\n    def __init__(self, *args, **kw):  # pragma: no cover\n        super().__init__(*args, **kw)\n\n        self.servers = {}\n        self.exit_code = 0\n\n    def init_process(self):\n        # create new event_loop after fork\n        asyncio.get_event_loop().close()\n\n        self.loop = asyncio.new_event_loop()\n        asyncio.set_event_loop(self.loop)\n\n        super().init_process()\n\n    def run(self):\n        self.loop.run_until_complete(self.wsgi.startup())\n        self._runner = ensure_future(self._run(), loop=self.loop)\n\n        try:\n            self.loop.run_until_complete(self._runner)\n        finally:\n            self.loop.close()\n\n        sys.exit(self.exit_code)\n\n    def make_handler(self, app):\n        return app.make_handler(\n            logger=self.log,\n            debug=self.cfg.debug,\n            timeout=self.cfg.timeout,\n            keep_alive=self.cfg.keepalive,\n            access_log=self.log.access_log,\n            access_log_format=self._get_valid_log_format(\n                self.cfg.access_log_format))\n\n    @asyncio.coroutine\n    def close(self):\n        if self.servers:\n            servers = self.servers\n            self.servers = None\n\n            # stop accepting connections\n            for server, handler in servers.items():\n                self.log.info(\"Stopping server: %s, connections: %s\",\n                              self.pid, len(handler.connections))\n                server.close()\n                yield from server.wait_closed()\n\n            # send on_shutdown event\n            yield from self.wsgi.shutdown()\n\n            # stop alive connections\n            tasks = [\n                handler.finish_connections(\n                    timeout=self.cfg.graceful_timeout / 100 * 95)\n                for handler in servers.values()]\n            yield from asyncio.gather(*tasks, loop=self.loop)\n\n            # cleanup application\n            yield from self.wsgi.cleanup()\n\n    @asyncio.coroutine\n    def _run(self):\n\n        ctx = self._create_ssl_context(self.cfg) if self.cfg.is_ssl else None\n\n        for sock in self.sockets:\n            handler = self.make_handler(self.wsgi)\n            srv = yield from self.loop.create_server(handler, sock=sock.sock,\n                                                     ssl=ctx)\n            self.servers[srv] = handler\n\n        # If our parent changed then we shut down.\n        pid = os.getpid()\n        try:\n            while self.alive:\n                self.notify()\n\n                cnt = sum(handler.requests_count\n                          for handler in self.servers.values())\n                if self.cfg.max_requests and cnt > self.cfg.max_requests:\n                    self.alive = False\n                    self.log.info(\"Max requests, shutting down: %s\", self)\n\n                elif pid == os.getpid() and self.ppid != os.getppid():\n                    self.alive = False\n                    self.log.info(\"Parent changed, shutting down: %s\", self)\n                else:\n                    yield from asyncio.sleep(1.0, loop=self.loop)\n\n        except BaseException:\n            pass\n\n        yield from self.close()\n\n    def init_signals(self):\n        # Set up signals through the event loop API.\n\n        self.loop.add_signal_handler(signal.SIGQUIT, self.handle_quit,\n                                     signal.SIGQUIT, None)\n\n        self.loop.add_signal_handler(signal.SIGTERM, self.handle_exit,\n                                     signal.SIGTERM, None)\n\n        self.loop.add_signal_handler(signal.SIGINT, self.handle_quit,\n                                     signal.SIGINT, None)\n\n        self.loop.add_signal_handler(signal.SIGWINCH, self.handle_winch,\n                                     signal.SIGWINCH, None)\n\n        self.loop.add_signal_handler(signal.SIGUSR1, self.handle_usr1,\n                                     signal.SIGUSR1, None)\n\n        self.loop.add_signal_handler(signal.SIGABRT, self.handle_abort,\n                                     signal.SIGABRT, None)\n\n        # Don't let SIGTERM and SIGUSR1 disturb active requests\n        # by interrupting system calls\n        signal.siginterrupt(signal.SIGTERM, False)\n        signal.siginterrupt(signal.SIGUSR1, False)\n\n    def handle_quit(self, sig, frame):\n        self.alive = False\n\n    def handle_abort(self, sig, frame):\n        self.alive = False\n        self.exit_code = 1\n\n    @staticmethod\n    def _create_ssl_context(cfg):\n        \"\"\" Creates SSLContext instance for usage in asyncio.create_server.\n\n        See ssl.SSLSocket.__init__ for more details.\n        \"\"\"\n        ctx = ssl.SSLContext(cfg.ssl_version)\n        ctx.load_cert_chain(cfg.certfile, cfg.keyfile)\n        ctx.verify_mode = cfg.cert_reqs\n        if cfg.ca_certs:\n            ctx.load_verify_locations(cfg.ca_certs)\n        if cfg.ciphers:\n            ctx.set_ciphers(cfg.ciphers)\n        return ctx\n\n    def _get_valid_log_format(self, source_format):\n        if source_format == self.DEFAULT_GUNICORN_LOG_FORMAT:\n            return self.DEFAULT_AIOHTTP_LOG_FORMAT\n        elif re.search(r'%\\([^\\)]+\\)', source_format):\n            raise ValueError(\n                \"Gunicorn's style options in form of `%(name)s` are not \"\n                \"supported for the log formatting. Please use aiohttp's \"\n                \"format specification to configure access log formatting: \"\n                \"http://aiohttp.readthedocs.io/en/stable/logging.html\"\n                \"#format-specification\"\n            )\n        else:\n            return source_format\n\n\nclass GunicornUVLoopWebWorker(GunicornWebWorker):\n\n    def init_process(self):\n        import uvloop\n\n        # Close any existing event loop before setting a\n        # new policy.\n        asyncio.get_event_loop().close()\n\n        # Setup uvloop policy, so that every\n        # asyncio.get_event_loop() will create an instance\n        # of uvloop event loop.\n        asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())\n\n        super().init_process()\n", "path": "aiohttp/worker.py"}], "after_files": [{"content": "\"\"\"Async gunicorn worker for aiohttp.web\"\"\"\n\nimport asyncio\nimport logging\nimport os\nimport re\nimport signal\nimport ssl\nimport sys\n\nimport gunicorn.workers.base as base\nfrom gunicorn.config import AccessLogFormat as GunicornAccessLogFormat\n\nfrom aiohttp.helpers import AccessLogger, ensure_future\n\n__all__ = ('GunicornWebWorker', 'GunicornUVLoopWebWorker')\n\n\nclass GunicornWebWorker(base.Worker):\n\n    DEFAULT_AIOHTTP_LOG_FORMAT = AccessLogger.LOG_FORMAT\n    DEFAULT_GUNICORN_LOG_FORMAT = GunicornAccessLogFormat.default\n\n    def __init__(self, *args, **kw):  # pragma: no cover\n        super().__init__(*args, **kw)\n\n        self.servers = {}\n        self.exit_code = 0\n\n    def init_process(self):\n        # create new event_loop after fork\n        asyncio.get_event_loop().close()\n\n        self.loop = asyncio.new_event_loop()\n        asyncio.set_event_loop(self.loop)\n\n        super().init_process()\n\n    def run(self):\n        self.loop.run_until_complete(self.wsgi.startup())\n        self._runner = ensure_future(self._run(), loop=self.loop)\n\n        try:\n            self.loop.run_until_complete(self._runner)\n        finally:\n            self.loop.close()\n\n        sys.exit(self.exit_code)\n\n    def make_handler(self, app):\n        if hasattr(self.cfg, 'debug'):\n            is_debug = self.cfg.debug\n        else:\n            is_debug = self.log.loglevel == logging.DEBUG\n\n        return app.make_handler(\n            logger=self.log,\n            debug=is_debug,\n            slow_request_timeout=self.cfg.timeout,\n            keepalive_timeout=self.cfg.keepalive,\n            access_log=self.log.access_log,\n            access_log_format=self._get_valid_log_format(\n                self.cfg.access_log_format))\n\n    @asyncio.coroutine\n    def close(self):\n        if self.servers:\n            servers = self.servers\n            self.servers = None\n\n            # stop accepting connections\n            for server, handler in servers.items():\n                self.log.info(\"Stopping server: %s, connections: %s\",\n                              self.pid, len(handler.connections))\n                server.close()\n                yield from server.wait_closed()\n\n            # send on_shutdown event\n            yield from self.wsgi.shutdown()\n\n            # stop alive connections\n            tasks = [\n                handler.finish_connections(\n                    timeout=self.cfg.graceful_timeout / 100 * 95)\n                for handler in servers.values()]\n            yield from asyncio.gather(*tasks, loop=self.loop)\n\n            # cleanup application\n            yield from self.wsgi.cleanup()\n\n    @asyncio.coroutine\n    def _run(self):\n\n        ctx = self._create_ssl_context(self.cfg) if self.cfg.is_ssl else None\n\n        for sock in self.sockets:\n            handler = self.make_handler(self.wsgi)\n            srv = yield from self.loop.create_server(handler, sock=sock.sock,\n                                                     ssl=ctx)\n            self.servers[srv] = handler\n\n        # If our parent changed then we shut down.\n        pid = os.getpid()\n        try:\n            while self.alive:\n                self.notify()\n\n                cnt = sum(handler.requests_count\n                          for handler in self.servers.values())\n                if self.cfg.max_requests and cnt > self.cfg.max_requests:\n                    self.alive = False\n                    self.log.info(\"Max requests, shutting down: %s\", self)\n\n                elif pid == os.getpid() and self.ppid != os.getppid():\n                    self.alive = False\n                    self.log.info(\"Parent changed, shutting down: %s\", self)\n                else:\n                    yield from asyncio.sleep(1.0, loop=self.loop)\n\n        except BaseException:\n            pass\n\n        yield from self.close()\n\n    def init_signals(self):\n        # Set up signals through the event loop API.\n\n        self.loop.add_signal_handler(signal.SIGQUIT, self.handle_quit,\n                                     signal.SIGQUIT, None)\n\n        self.loop.add_signal_handler(signal.SIGTERM, self.handle_exit,\n                                     signal.SIGTERM, None)\n\n        self.loop.add_signal_handler(signal.SIGINT, self.handle_quit,\n                                     signal.SIGINT, None)\n\n        self.loop.add_signal_handler(signal.SIGWINCH, self.handle_winch,\n                                     signal.SIGWINCH, None)\n\n        self.loop.add_signal_handler(signal.SIGUSR1, self.handle_usr1,\n                                     signal.SIGUSR1, None)\n\n        self.loop.add_signal_handler(signal.SIGABRT, self.handle_abort,\n                                     signal.SIGABRT, None)\n\n        # Don't let SIGTERM and SIGUSR1 disturb active requests\n        # by interrupting system calls\n        signal.siginterrupt(signal.SIGTERM, False)\n        signal.siginterrupt(signal.SIGUSR1, False)\n\n    def handle_quit(self, sig, frame):\n        self.alive = False\n\n    def handle_abort(self, sig, frame):\n        self.alive = False\n        self.exit_code = 1\n\n    @staticmethod\n    def _create_ssl_context(cfg):\n        \"\"\" Creates SSLContext instance for usage in asyncio.create_server.\n\n        See ssl.SSLSocket.__init__ for more details.\n        \"\"\"\n        ctx = ssl.SSLContext(cfg.ssl_version)\n        ctx.load_cert_chain(cfg.certfile, cfg.keyfile)\n        ctx.verify_mode = cfg.cert_reqs\n        if cfg.ca_certs:\n            ctx.load_verify_locations(cfg.ca_certs)\n        if cfg.ciphers:\n            ctx.set_ciphers(cfg.ciphers)\n        return ctx\n\n    def _get_valid_log_format(self, source_format):\n        if source_format == self.DEFAULT_GUNICORN_LOG_FORMAT:\n            return self.DEFAULT_AIOHTTP_LOG_FORMAT\n        elif re.search(r'%\\([^\\)]+\\)', source_format):\n            raise ValueError(\n                \"Gunicorn's style options in form of `%(name)s` are not \"\n                \"supported for the log formatting. Please use aiohttp's \"\n                \"format specification to configure access log formatting: \"\n                \"http://aiohttp.readthedocs.io/en/stable/logging.html\"\n                \"#format-specification\"\n            )\n        else:\n            return source_format\n\n\nclass GunicornUVLoopWebWorker(GunicornWebWorker):\n\n    def init_process(self):\n        import uvloop\n\n        # Close any existing event loop before setting a\n        # new policy.\n        asyncio.get_event_loop().close()\n\n        # Setup uvloop policy, so that every\n        # asyncio.get_event_loop() will create an instance\n        # of uvloop event loop.\n        asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())\n\n        super().init_process()\n", "path": "aiohttp/worker.py"}]}