MCPcopy
hub / github.com/benoitc/gunicorn / run

Method run

gunicorn/workers/ggevent.py:56–114  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

54 return gevent.Timeout(self.cfg.keepalive, False)
55
56 def run(self):
57 servers = []
58 ssl_args = {}
59
60 if self.cfg.is_ssl:
61 ssl_args = {"ssl_context": ssl_context(self.cfg)}
62
63 for s in self.sockets:
64 s.setblocking(1)
65 pool = Pool(self.worker_connections)
66 if self.server_class is not None:
67 environ = base_environ(self.cfg)
68 environ.update({
69 "wsgi.multithread": True,
70 "SERVER_SOFTWARE": VERSION,
71 })
72 server = self.server_class(
73 s, application=self.wsgi, spawn=pool, log=self.log,
74 handler_class=self.wsgi_handler, environ=environ,
75 **ssl_args)
76 else:
77 hfun = partial(self.handle, s)
78 server = StreamServer(s, handle=hfun, spawn=pool, **ssl_args)
79 if self.cfg.workers > 1:
80 server.max_accept = 1
81
82 server.start()
83 servers.append(server)
84
85 while self.alive:
86 self.notify()
87 gevent.sleep(1.0)
88
89 try:
90 # Stop accepting requests
91 for server in servers:
92 server.close()
93
94 # Handle current requests until graceful_timeout
95 ts = time.time()
96 while time.time() - ts <= self.cfg.graceful_timeout:
97 accepting = 0
98 for server in servers:
99 if server.pool.free_count() != server.pool.size:
100 accepting += 1
101
102 # if no server is accepting a connection, we can exit
103 if not accepting:
104 return
105
106 self.notify()
107 gevent.sleep(1.0)
108
109 # Force kill all the active handlers
110 self.log.warning("Worker graceful timeout (pid:%s)", self.pid)
111 for server in servers:
112 server.stop(timeout=1)
113 except Exception:

Callers

nothing calls this directly

Calls 8

notifyMethod · 0.95
ssl_contextFunction · 0.90
base_environFunction · 0.90
setblockingMethod · 0.45
startMethod · 0.45
closeMethod · 0.45
warningMethod · 0.45
stopMethod · 0.45

Tested by

no test coverage detected