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

Method defer

gunicorn/workers/gthread.py:175–189  ·  view source on GitHub ↗

Queue a callback to be run on the main thread. The callback is added to the queue first, then a wake-up byte is written to the pipe. If the pipe write fails (buffer full), it's safe to ignore because the main thread will eventually drain the queue when it reads other

(self, callback, *args)

Source from the content-addressed store, hash-verified

173 return self._read_fd
174
175 def defer(self, callback, *args):
176 """Queue a callback to be run on the main thread.
177
178 The callback is added to the queue first, then a wake-up byte
179 is written to the pipe. If the pipe write fails (buffer full),
180 it's safe to ignore because the main thread will eventually
181 drain the queue when it reads other wake-up bytes.
182 """
183 self._queue.put(partial(callback, *args))
184 try:
185 os.write(self._write_fd, b'\x00')
186 except OSError:
187 # Pipe buffer full (EAGAIN/EWOULDBLOCK) - safe to ignore
188 # The main thread will still process the queue
189 pass
190
191 def run_callbacks(self, _fileobj, max_callbacks=50):
192 """Run queued callbacks. Called when the pipe is readable.

Callers 5

handle_exitMethod · 0.80
enqueue_reqMethod · 0.80
add_callbackMethod · 0.80

Calls 2

putMethod · 0.80
writeMethod · 0.45

Tested by 3

add_callbackMethod · 0.64