We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
I get error in this package AttributeError: 'NoneType' object has no attribute 'add_extra_file'
hi every one ..
when i try to deploy keras model into google cloud i get this error ...

```py
File "/home/falahgs07/keras/env/lib/python3.5/site-packages/gunicorn/workers/base.py", line 126, in init_process
    self.load_wsgi()
  File "/home/falahgs07/keras/env/lib/python3.5/site-packages/gunicorn/workers/base.py", line 148, in load_wsgi
    self.reloader.add_extra_file(exc_val.filename)
AttributeError: 'NoneType' object has no attribute 'add_extra_file'
```

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `gunicorn/workers/base.py`
Content:
```
1 # -*- coding: utf-8 -
2 #
3 # This file is part of gunicorn released under the MIT license.
4 # See the NOTICE for more information.
5 
6 from datetime import datetime
7 import os
8 from random import randint
9 import signal
10 from ssl import SSLError
11 import sys
12 import time
13 import traceback
14 
15 from gunicorn import six
16 from gunicorn import util
17 from gunicorn.workers.workertmp import WorkerTmp
18 from gunicorn.reloader import reloader_engines
19 from gunicorn.http.errors import (
20     InvalidHeader, InvalidHeaderName, InvalidRequestLine, InvalidRequestMethod,
21     InvalidHTTPVersion, LimitRequestLine, LimitRequestHeaders,
22 )
23 from gunicorn.http.errors import InvalidProxyLine, ForbiddenProxyRequest
24 from gunicorn.http.errors import InvalidSchemeHeaders
25 from gunicorn.http.wsgi import default_environ, Response
26 from gunicorn.six import MAXSIZE
27 
28 
29 class Worker(object):
30 
31     SIGNALS = [getattr(signal, "SIG%s" % x)
32             for x in "ABRT HUP QUIT INT TERM USR1 USR2 WINCH CHLD".split()]
33 
34     PIPE = []
35 
36     def __init__(self, age, ppid, sockets, app, timeout, cfg, log):
37         """\
38         This is called pre-fork so it shouldn't do anything to the
39         current process. If there's a need to make process wide
40         changes you'll want to do that in ``self.init_process()``.
41         """
42         self.age = age
43         self.pid = "[booting]"
44         self.ppid = ppid
45         self.sockets = sockets
46         self.app = app
47         self.timeout = timeout
48         self.cfg = cfg
49         self.booted = False
50         self.aborted = False
51         self.reloader = None
52 
53         self.nr = 0
54         jitter = randint(0, cfg.max_requests_jitter)
55         self.max_requests = cfg.max_requests + jitter or MAXSIZE
56         self.alive = True
57         self.log = log
58         self.tmp = WorkerTmp(cfg)
59 
60     def __str__(self):
61         return "<Worker %s>" % self.pid
62 
63     def notify(self):
64         """\
65         Your worker subclass must arrange to have this method called
66         once every ``self.timeout`` seconds. If you fail in accomplishing
67         this task, the master process will murder your workers.
68         """
69         self.tmp.notify()
70 
71     def run(self):
72         """\
73         This is the mainloop of a worker process. You should override
74         this method in a subclass to provide the intended behaviour
75         for your particular evil schemes.
76         """
77         raise NotImplementedError()
78 
79     def init_process(self):
80         """\
81         If you override this method in a subclass, the last statement
82         in the function should be to call this method with
83         super(MyWorkerClass, self).init_process() so that the ``run()``
84         loop is initiated.
85         """
86 
87         # set environment' variables
88         if self.cfg.env:
89             for k, v in self.cfg.env.items():
90                 os.environ[k] = v
91 
92         util.set_owner_process(self.cfg.uid, self.cfg.gid,
93                                initgroups=self.cfg.initgroups)
94 
95         # Reseed the random number generator
96         util.seed()
97 
98         # For waking ourselves up
99         self.PIPE = os.pipe()
100         for p in self.PIPE:
101             util.set_non_blocking(p)
102             util.close_on_exec(p)
103 
104         # Prevent fd inheritance
105         for s in self.sockets:
106             util.close_on_exec(s)
107         util.close_on_exec(self.tmp.fileno())
108 
109         self.wait_fds = self.sockets + [self.PIPE[0]]
110 
111         self.log.close_on_exec()
112 
113         self.init_signals()
114 
115         # start the reloader
116         if self.cfg.reload:
117             def changed(fname):
118                 self.log.info("Worker reloading: %s modified", fname)
119                 self.alive = False
120                 self.cfg.worker_int(self)
121                 time.sleep(0.1)
122                 sys.exit(0)
123 
124             reloader_cls = reloader_engines[self.cfg.reload_engine]
125             self.reloader = reloader_cls(extra_files=self.cfg.reload_extra_files,
126                                          callback=changed)
127             self.reloader.start()
128 
129         self.load_wsgi()
130         self.cfg.post_worker_init(self)
131 
132         # Enter main run loop
133         self.booted = True
134         self.run()
135 
136     def load_wsgi(self):
137         try:
138             self.wsgi = self.app.wsgi()
139         except SyntaxError as e:
140             if self.cfg.reload == 'off':
141                 raise
142 
143             self.log.exception(e)
144 
145             # fix from PR #1228
146             # storing the traceback into exc_tb will create a circular reference.
147             # per https://docs.python.org/2/library/sys.html#sys.exc_info warning,
148             # delete the traceback after use.
149             try:
150                 _, exc_val, exc_tb = sys.exc_info()
151                 self.reloader.add_extra_file(exc_val.filename)
152 
153                 tb_string = six.StringIO()
154                 traceback.print_tb(exc_tb, file=tb_string)
155                 self.wsgi = util.make_fail_app(tb_string.getvalue())
156             finally:
157                 del exc_tb
158 
159     def init_signals(self):
160         # reset signaling
161         for s in self.SIGNALS:
162             signal.signal(s, signal.SIG_DFL)
163         # init new signaling
164         signal.signal(signal.SIGQUIT, self.handle_quit)
165         signal.signal(signal.SIGTERM, self.handle_exit)
166         signal.signal(signal.SIGINT, self.handle_quit)
167         signal.signal(signal.SIGWINCH, self.handle_winch)
168         signal.signal(signal.SIGUSR1, self.handle_usr1)
169         signal.signal(signal.SIGABRT, self.handle_abort)
170 
171         # Don't let SIGTERM and SIGUSR1 disturb active requests
172         # by interrupting system calls
173         if hasattr(signal, 'siginterrupt'):  # python >= 2.6
174             signal.siginterrupt(signal.SIGTERM, False)
175             signal.siginterrupt(signal.SIGUSR1, False)
176 
177         if hasattr(signal, 'set_wakeup_fd'):
178             signal.set_wakeup_fd(self.PIPE[1])
179 
180     def handle_usr1(self, sig, frame):
181         self.log.reopen_files()
182 
183     def handle_exit(self, sig, frame):
184         self.alive = False
185 
186     def handle_quit(self, sig, frame):
187         self.alive = False
188         # worker_int callback
189         self.cfg.worker_int(self)
190         time.sleep(0.1)
191         sys.exit(0)
192 
193     def handle_abort(self, sig, frame):
194         self.alive = False
195         self.cfg.worker_abort(self)
196         sys.exit(1)
197 
198     def handle_error(self, req, client, addr, exc):
199         request_start = datetime.now()
200         addr = addr or ('', -1)  # unix socket case
201         if isinstance(exc, (InvalidRequestLine, InvalidRequestMethod,
202                 InvalidHTTPVersion, InvalidHeader, InvalidHeaderName,
203                 LimitRequestLine, LimitRequestHeaders,
204                 InvalidProxyLine, ForbiddenProxyRequest,
205                 InvalidSchemeHeaders,
206                 SSLError)):
207 
208             status_int = 400
209             reason = "Bad Request"
210 
211             if isinstance(exc, InvalidRequestLine):
212                 mesg = "Invalid Request Line '%s'" % str(exc)
213             elif isinstance(exc, InvalidRequestMethod):
214                 mesg = "Invalid Method '%s'" % str(exc)
215             elif isinstance(exc, InvalidHTTPVersion):
216                 mesg = "Invalid HTTP Version '%s'" % str(exc)
217             elif isinstance(exc, (InvalidHeaderName, InvalidHeader,)):
218                 mesg = "%s" % str(exc)
219                 if not req and hasattr(exc, "req"):
220                     req = exc.req  # for access log
221             elif isinstance(exc, LimitRequestLine):
222                 mesg = "%s" % str(exc)
223             elif isinstance(exc, LimitRequestHeaders):
224                 mesg = "Error parsing headers: '%s'" % str(exc)
225             elif isinstance(exc, InvalidProxyLine):
226                 mesg = "'%s'" % str(exc)
227             elif isinstance(exc, ForbiddenProxyRequest):
228                 reason = "Forbidden"
229                 mesg = "Request forbidden"
230                 status_int = 403
231             elif isinstance(exc, InvalidSchemeHeaders):
232                 mesg = "%s" % str(exc)
233             elif isinstance(exc, SSLError):
234                 reason = "Forbidden"
235                 mesg = "'%s'" % str(exc)
236                 status_int = 403
237 
238             msg = "Invalid request from ip={ip}: {error}"
239             self.log.debug(msg.format(ip=addr[0], error=str(exc)))
240         else:
241             if hasattr(req, "uri"):
242                 self.log.exception("Error handling request %s", req.uri)
243             status_int = 500
244             reason = "Internal Server Error"
245             mesg = ""
246 
247         if req is not None:
248             request_time = datetime.now() - request_start
249             environ = default_environ(req, client, self.cfg)
250             environ['REMOTE_ADDR'] = addr[0]
251             environ['REMOTE_PORT'] = str(addr[1])
252             resp = Response(req, client, self.cfg)
253             resp.status = "%s %s" % (status_int, reason)
254             resp.response_length = len(mesg)
255             self.log.access(resp, req, environ, request_time)
256 
257         try:
258             util.write_error(client, status_int, reason, mesg)
259         except:
260             self.log.debug("Failed to send error message.")
261 
262     def handle_winch(self, sig, fname):
263         # Ignore SIGWINCH in worker. Fixes a crash on OpenBSD.
264         self.log.debug("worker: SIGWINCH ignored.")
265
```
--- 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/gunicorn/workers/base.py b/gunicorn/workers/base.py
--- a/gunicorn/workers/base.py
+++ b/gunicorn/workers/base.py
@@ -137,7 +137,7 @@
         try:
             self.wsgi = self.app.wsgi()
         except SyntaxError as e:
-            if self.cfg.reload == 'off':
+            if not self.cfg.reload:
                 raise
 
             self.log.exception(e)

{"golden_diff": "diff --git a/gunicorn/workers/base.py b/gunicorn/workers/base.py\n--- a/gunicorn/workers/base.py\n+++ b/gunicorn/workers/base.py\n@@ -137,7 +137,7 @@\n         try:\n             self.wsgi = self.app.wsgi()\n         except SyntaxError as e:\n-            if self.cfg.reload == 'off':\n+            if not self.cfg.reload:\n                 raise\n \n             self.log.exception(e)\n", "issue": "I get error in this package AttributeError: 'NoneType' object has no attribute 'add_extra_file'\nhi every one ..\r\nwhen i try to deploy keras model into google cloud i get this error ...\r\n\r\n```py\r\nFile \"/home/falahgs07/keras/env/lib/python3.5/site-packages/gunicorn/workers/base.py\", line 126, in init_process\r\n    self.load_wsgi()\r\n  File \"/home/falahgs07/keras/env/lib/python3.5/site-packages/gunicorn/workers/base.py\", line 148, in load_wsgi\r\n    self.reloader.add_extra_file(exc_val.filename)\r\nAttributeError: 'NoneType' object has no attribute 'add_extra_file'\r\n```\n", "before_files": [{"content": "# -*- coding: utf-8 -\n#\n# This file is part of gunicorn released under the MIT license.\n# See the NOTICE for more information.\n\nfrom datetime import datetime\nimport os\nfrom random import randint\nimport signal\nfrom ssl import SSLError\nimport sys\nimport time\nimport traceback\n\nfrom gunicorn import six\nfrom gunicorn import util\nfrom gunicorn.workers.workertmp import WorkerTmp\nfrom gunicorn.reloader import reloader_engines\nfrom gunicorn.http.errors import (\n    InvalidHeader, InvalidHeaderName, InvalidRequestLine, InvalidRequestMethod,\n    InvalidHTTPVersion, LimitRequestLine, LimitRequestHeaders,\n)\nfrom gunicorn.http.errors import InvalidProxyLine, ForbiddenProxyRequest\nfrom gunicorn.http.errors import InvalidSchemeHeaders\nfrom gunicorn.http.wsgi import default_environ, Response\nfrom gunicorn.six import MAXSIZE\n\n\nclass Worker(object):\n\n    SIGNALS = [getattr(signal, \"SIG%s\" % x)\n            for x in \"ABRT HUP QUIT INT TERM USR1 USR2 WINCH CHLD\".split()]\n\n    PIPE = []\n\n    def __init__(self, age, ppid, sockets, app, timeout, cfg, log):\n        \"\"\"\\\n        This is called pre-fork so it shouldn't do anything to the\n        current process. If there's a need to make process wide\n        changes you'll want to do that in ``self.init_process()``.\n        \"\"\"\n        self.age = age\n        self.pid = \"[booting]\"\n        self.ppid = ppid\n        self.sockets = sockets\n        self.app = app\n        self.timeout = timeout\n        self.cfg = cfg\n        self.booted = False\n        self.aborted = False\n        self.reloader = None\n\n        self.nr = 0\n        jitter = randint(0, cfg.max_requests_jitter)\n        self.max_requests = cfg.max_requests + jitter or MAXSIZE\n        self.alive = True\n        self.log = log\n        self.tmp = WorkerTmp(cfg)\n\n    def __str__(self):\n        return \"<Worker %s>\" % self.pid\n\n    def notify(self):\n        \"\"\"\\\n        Your worker subclass must arrange to have this method called\n        once every ``self.timeout`` seconds. If you fail in accomplishing\n        this task, the master process will murder your workers.\n        \"\"\"\n        self.tmp.notify()\n\n    def run(self):\n        \"\"\"\\\n        This is the mainloop of a worker process. You should override\n        this method in a subclass to provide the intended behaviour\n        for your particular evil schemes.\n        \"\"\"\n        raise NotImplementedError()\n\n    def init_process(self):\n        \"\"\"\\\n        If you override this method in a subclass, the last statement\n        in the function should be to call this method with\n        super(MyWorkerClass, self).init_process() so that the ``run()``\n        loop is initiated.\n        \"\"\"\n\n        # set environment' variables\n        if self.cfg.env:\n            for k, v in self.cfg.env.items():\n                os.environ[k] = v\n\n        util.set_owner_process(self.cfg.uid, self.cfg.gid,\n                               initgroups=self.cfg.initgroups)\n\n        # Reseed the random number generator\n        util.seed()\n\n        # For waking ourselves up\n        self.PIPE = os.pipe()\n        for p in self.PIPE:\n            util.set_non_blocking(p)\n            util.close_on_exec(p)\n\n        # Prevent fd inheritance\n        for s in self.sockets:\n            util.close_on_exec(s)\n        util.close_on_exec(self.tmp.fileno())\n\n        self.wait_fds = self.sockets + [self.PIPE[0]]\n\n        self.log.close_on_exec()\n\n        self.init_signals()\n\n        # start the reloader\n        if self.cfg.reload:\n            def changed(fname):\n                self.log.info(\"Worker reloading: %s modified\", fname)\n                self.alive = False\n                self.cfg.worker_int(self)\n                time.sleep(0.1)\n                sys.exit(0)\n\n            reloader_cls = reloader_engines[self.cfg.reload_engine]\n            self.reloader = reloader_cls(extra_files=self.cfg.reload_extra_files,\n                                         callback=changed)\n            self.reloader.start()\n\n        self.load_wsgi()\n        self.cfg.post_worker_init(self)\n\n        # Enter main run loop\n        self.booted = True\n        self.run()\n\n    def load_wsgi(self):\n        try:\n            self.wsgi = self.app.wsgi()\n        except SyntaxError as e:\n            if self.cfg.reload == 'off':\n                raise\n\n            self.log.exception(e)\n\n            # fix from PR #1228\n            # storing the traceback into exc_tb will create a circular reference.\n            # per https://docs.python.org/2/library/sys.html#sys.exc_info warning,\n            # delete the traceback after use.\n            try:\n                _, exc_val, exc_tb = sys.exc_info()\n                self.reloader.add_extra_file(exc_val.filename)\n\n                tb_string = six.StringIO()\n                traceback.print_tb(exc_tb, file=tb_string)\n                self.wsgi = util.make_fail_app(tb_string.getvalue())\n            finally:\n                del exc_tb\n\n    def init_signals(self):\n        # reset signaling\n        for s in self.SIGNALS:\n            signal.signal(s, signal.SIG_DFL)\n        # init new signaling\n        signal.signal(signal.SIGQUIT, self.handle_quit)\n        signal.signal(signal.SIGTERM, self.handle_exit)\n        signal.signal(signal.SIGINT, self.handle_quit)\n        signal.signal(signal.SIGWINCH, self.handle_winch)\n        signal.signal(signal.SIGUSR1, self.handle_usr1)\n        signal.signal(signal.SIGABRT, self.handle_abort)\n\n        # Don't let SIGTERM and SIGUSR1 disturb active requests\n        # by interrupting system calls\n        if hasattr(signal, 'siginterrupt'):  # python >= 2.6\n            signal.siginterrupt(signal.SIGTERM, False)\n            signal.siginterrupt(signal.SIGUSR1, False)\n\n        if hasattr(signal, 'set_wakeup_fd'):\n            signal.set_wakeup_fd(self.PIPE[1])\n\n    def handle_usr1(self, sig, frame):\n        self.log.reopen_files()\n\n    def handle_exit(self, sig, frame):\n        self.alive = False\n\n    def handle_quit(self, sig, frame):\n        self.alive = False\n        # worker_int callback\n        self.cfg.worker_int(self)\n        time.sleep(0.1)\n        sys.exit(0)\n\n    def handle_abort(self, sig, frame):\n        self.alive = False\n        self.cfg.worker_abort(self)\n        sys.exit(1)\n\n    def handle_error(self, req, client, addr, exc):\n        request_start = datetime.now()\n        addr = addr or ('', -1)  # unix socket case\n        if isinstance(exc, (InvalidRequestLine, InvalidRequestMethod,\n                InvalidHTTPVersion, InvalidHeader, InvalidHeaderName,\n                LimitRequestLine, LimitRequestHeaders,\n                InvalidProxyLine, ForbiddenProxyRequest,\n                InvalidSchemeHeaders,\n                SSLError)):\n\n            status_int = 400\n            reason = \"Bad Request\"\n\n            if isinstance(exc, InvalidRequestLine):\n                mesg = \"Invalid Request Line '%s'\" % str(exc)\n            elif isinstance(exc, InvalidRequestMethod):\n                mesg = \"Invalid Method '%s'\" % str(exc)\n            elif isinstance(exc, InvalidHTTPVersion):\n                mesg = \"Invalid HTTP Version '%s'\" % str(exc)\n            elif isinstance(exc, (InvalidHeaderName, InvalidHeader,)):\n                mesg = \"%s\" % str(exc)\n                if not req and hasattr(exc, \"req\"):\n                    req = exc.req  # for access log\n            elif isinstance(exc, LimitRequestLine):\n                mesg = \"%s\" % str(exc)\n            elif isinstance(exc, LimitRequestHeaders):\n                mesg = \"Error parsing headers: '%s'\" % str(exc)\n            elif isinstance(exc, InvalidProxyLine):\n                mesg = \"'%s'\" % str(exc)\n            elif isinstance(exc, ForbiddenProxyRequest):\n                reason = \"Forbidden\"\n                mesg = \"Request forbidden\"\n                status_int = 403\n            elif isinstance(exc, InvalidSchemeHeaders):\n                mesg = \"%s\" % str(exc)\n            elif isinstance(exc, SSLError):\n                reason = \"Forbidden\"\n                mesg = \"'%s'\" % str(exc)\n                status_int = 403\n\n            msg = \"Invalid request from ip={ip}: {error}\"\n            self.log.debug(msg.format(ip=addr[0], error=str(exc)))\n        else:\n            if hasattr(req, \"uri\"):\n                self.log.exception(\"Error handling request %s\", req.uri)\n            status_int = 500\n            reason = \"Internal Server Error\"\n            mesg = \"\"\n\n        if req is not None:\n            request_time = datetime.now() - request_start\n            environ = default_environ(req, client, self.cfg)\n            environ['REMOTE_ADDR'] = addr[0]\n            environ['REMOTE_PORT'] = str(addr[1])\n            resp = Response(req, client, self.cfg)\n            resp.status = \"%s %s\" % (status_int, reason)\n            resp.response_length = len(mesg)\n            self.log.access(resp, req, environ, request_time)\n\n        try:\n            util.write_error(client, status_int, reason, mesg)\n        except:\n            self.log.debug(\"Failed to send error message.\")\n\n    def handle_winch(self, sig, fname):\n        # Ignore SIGWINCH in worker. Fixes a crash on OpenBSD.\n        self.log.debug(\"worker: SIGWINCH ignored.\")\n", "path": "gunicorn/workers/base.py"}], "after_files": [{"content": "# -*- coding: utf-8 -\n#\n# This file is part of gunicorn released under the MIT license.\n# See the NOTICE for more information.\n\nfrom datetime import datetime\nimport os\nfrom random import randint\nimport signal\nfrom ssl import SSLError\nimport sys\nimport time\nimport traceback\n\nfrom gunicorn import six\nfrom gunicorn import util\nfrom gunicorn.workers.workertmp import WorkerTmp\nfrom gunicorn.reloader import reloader_engines\nfrom gunicorn.http.errors import (\n    InvalidHeader, InvalidHeaderName, InvalidRequestLine, InvalidRequestMethod,\n    InvalidHTTPVersion, LimitRequestLine, LimitRequestHeaders,\n)\nfrom gunicorn.http.errors import InvalidProxyLine, ForbiddenProxyRequest\nfrom gunicorn.http.errors import InvalidSchemeHeaders\nfrom gunicorn.http.wsgi import default_environ, Response\nfrom gunicorn.six import MAXSIZE\n\n\nclass Worker(object):\n\n    SIGNALS = [getattr(signal, \"SIG%s\" % x)\n            for x in \"ABRT HUP QUIT INT TERM USR1 USR2 WINCH CHLD\".split()]\n\n    PIPE = []\n\n    def __init__(self, age, ppid, sockets, app, timeout, cfg, log):\n        \"\"\"\\\n        This is called pre-fork so it shouldn't do anything to the\n        current process. If there's a need to make process wide\n        changes you'll want to do that in ``self.init_process()``.\n        \"\"\"\n        self.age = age\n        self.pid = \"[booting]\"\n        self.ppid = ppid\n        self.sockets = sockets\n        self.app = app\n        self.timeout = timeout\n        self.cfg = cfg\n        self.booted = False\n        self.aborted = False\n        self.reloader = None\n\n        self.nr = 0\n        jitter = randint(0, cfg.max_requests_jitter)\n        self.max_requests = cfg.max_requests + jitter or MAXSIZE\n        self.alive = True\n        self.log = log\n        self.tmp = WorkerTmp(cfg)\n\n    def __str__(self):\n        return \"<Worker %s>\" % self.pid\n\n    def notify(self):\n        \"\"\"\\\n        Your worker subclass must arrange to have this method called\n        once every ``self.timeout`` seconds. If you fail in accomplishing\n        this task, the master process will murder your workers.\n        \"\"\"\n        self.tmp.notify()\n\n    def run(self):\n        \"\"\"\\\n        This is the mainloop of a worker process. You should override\n        this method in a subclass to provide the intended behaviour\n        for your particular evil schemes.\n        \"\"\"\n        raise NotImplementedError()\n\n    def init_process(self):\n        \"\"\"\\\n        If you override this method in a subclass, the last statement\n        in the function should be to call this method with\n        super(MyWorkerClass, self).init_process() so that the ``run()``\n        loop is initiated.\n        \"\"\"\n\n        # set environment' variables\n        if self.cfg.env:\n            for k, v in self.cfg.env.items():\n                os.environ[k] = v\n\n        util.set_owner_process(self.cfg.uid, self.cfg.gid,\n                               initgroups=self.cfg.initgroups)\n\n        # Reseed the random number generator\n        util.seed()\n\n        # For waking ourselves up\n        self.PIPE = os.pipe()\n        for p in self.PIPE:\n            util.set_non_blocking(p)\n            util.close_on_exec(p)\n\n        # Prevent fd inheritance\n        for s in self.sockets:\n            util.close_on_exec(s)\n        util.close_on_exec(self.tmp.fileno())\n\n        self.wait_fds = self.sockets + [self.PIPE[0]]\n\n        self.log.close_on_exec()\n\n        self.init_signals()\n\n        # start the reloader\n        if self.cfg.reload:\n            def changed(fname):\n                self.log.info(\"Worker reloading: %s modified\", fname)\n                self.alive = False\n                self.cfg.worker_int(self)\n                time.sleep(0.1)\n                sys.exit(0)\n\n            reloader_cls = reloader_engines[self.cfg.reload_engine]\n            self.reloader = reloader_cls(extra_files=self.cfg.reload_extra_files,\n                                         callback=changed)\n            self.reloader.start()\n\n        self.load_wsgi()\n        self.cfg.post_worker_init(self)\n\n        # Enter main run loop\n        self.booted = True\n        self.run()\n\n    def load_wsgi(self):\n        try:\n            self.wsgi = self.app.wsgi()\n        except SyntaxError as e:\n            if not self.cfg.reload:\n                raise\n\n            self.log.exception(e)\n\n            # fix from PR #1228\n            # storing the traceback into exc_tb will create a circular reference.\n            # per https://docs.python.org/2/library/sys.html#sys.exc_info warning,\n            # delete the traceback after use.\n            try:\n                _, exc_val, exc_tb = sys.exc_info()\n                self.reloader.add_extra_file(exc_val.filename)\n\n                tb_string = six.StringIO()\n                traceback.print_tb(exc_tb, file=tb_string)\n                self.wsgi = util.make_fail_app(tb_string.getvalue())\n            finally:\n                del exc_tb\n\n    def init_signals(self):\n        # reset signaling\n        for s in self.SIGNALS:\n            signal.signal(s, signal.SIG_DFL)\n        # init new signaling\n        signal.signal(signal.SIGQUIT, self.handle_quit)\n        signal.signal(signal.SIGTERM, self.handle_exit)\n        signal.signal(signal.SIGINT, self.handle_quit)\n        signal.signal(signal.SIGWINCH, self.handle_winch)\n        signal.signal(signal.SIGUSR1, self.handle_usr1)\n        signal.signal(signal.SIGABRT, self.handle_abort)\n\n        # Don't let SIGTERM and SIGUSR1 disturb active requests\n        # by interrupting system calls\n        if hasattr(signal, 'siginterrupt'):  # python >= 2.6\n            signal.siginterrupt(signal.SIGTERM, False)\n            signal.siginterrupt(signal.SIGUSR1, False)\n\n        if hasattr(signal, 'set_wakeup_fd'):\n            signal.set_wakeup_fd(self.PIPE[1])\n\n    def handle_usr1(self, sig, frame):\n        self.log.reopen_files()\n\n    def handle_exit(self, sig, frame):\n        self.alive = False\n\n    def handle_quit(self, sig, frame):\n        self.alive = False\n        # worker_int callback\n        self.cfg.worker_int(self)\n        time.sleep(0.1)\n        sys.exit(0)\n\n    def handle_abort(self, sig, frame):\n        self.alive = False\n        self.cfg.worker_abort(self)\n        sys.exit(1)\n\n    def handle_error(self, req, client, addr, exc):\n        request_start = datetime.now()\n        addr = addr or ('', -1)  # unix socket case\n        if isinstance(exc, (InvalidRequestLine, InvalidRequestMethod,\n                InvalidHTTPVersion, InvalidHeader, InvalidHeaderName,\n                LimitRequestLine, LimitRequestHeaders,\n                InvalidProxyLine, ForbiddenProxyRequest,\n                InvalidSchemeHeaders,\n                SSLError)):\n\n            status_int = 400\n            reason = \"Bad Request\"\n\n            if isinstance(exc, InvalidRequestLine):\n                mesg = \"Invalid Request Line '%s'\" % str(exc)\n            elif isinstance(exc, InvalidRequestMethod):\n                mesg = \"Invalid Method '%s'\" % str(exc)\n            elif isinstance(exc, InvalidHTTPVersion):\n                mesg = \"Invalid HTTP Version '%s'\" % str(exc)\n            elif isinstance(exc, (InvalidHeaderName, InvalidHeader,)):\n                mesg = \"%s\" % str(exc)\n                if not req and hasattr(exc, \"req\"):\n                    req = exc.req  # for access log\n            elif isinstance(exc, LimitRequestLine):\n                mesg = \"%s\" % str(exc)\n            elif isinstance(exc, LimitRequestHeaders):\n                mesg = \"Error parsing headers: '%s'\" % str(exc)\n            elif isinstance(exc, InvalidProxyLine):\n                mesg = \"'%s'\" % str(exc)\n            elif isinstance(exc, ForbiddenProxyRequest):\n                reason = \"Forbidden\"\n                mesg = \"Request forbidden\"\n                status_int = 403\n            elif isinstance(exc, InvalidSchemeHeaders):\n                mesg = \"%s\" % str(exc)\n            elif isinstance(exc, SSLError):\n                reason = \"Forbidden\"\n                mesg = \"'%s'\" % str(exc)\n                status_int = 403\n\n            msg = \"Invalid request from ip={ip}: {error}\"\n            self.log.debug(msg.format(ip=addr[0], error=str(exc)))\n        else:\n            if hasattr(req, \"uri\"):\n                self.log.exception(\"Error handling request %s\", req.uri)\n            status_int = 500\n            reason = \"Internal Server Error\"\n            mesg = \"\"\n\n        if req is not None:\n            request_time = datetime.now() - request_start\n            environ = default_environ(req, client, self.cfg)\n            environ['REMOTE_ADDR'] = addr[0]\n            environ['REMOTE_PORT'] = str(addr[1])\n            resp = Response(req, client, self.cfg)\n            resp.status = \"%s %s\" % (status_int, reason)\n            resp.response_length = len(mesg)\n            self.log.access(resp, req, environ, request_time)\n\n        try:\n            util.write_error(client, status_int, reason, mesg)\n        except:\n            self.log.debug(\"Failed to send error message.\")\n\n    def handle_winch(self, sig, fname):\n        # Ignore SIGWINCH in worker. Fixes a crash on OpenBSD.\n        self.log.debug(\"worker: SIGWINCH ignored.\")\n", "path": "gunicorn/workers/base.py"}]}