MCPcopy
hub / github.com/celery/celery / safe_say

Function safe_say

celery/apps/worker.py:80–88  ·  view source on GitHub ↗

Uses the original (unpatched) os.write to avoid issues with eventlet/gevent monkey-patching. When using eventlet>=0.37.0, the patched os.write calls hubs.trampoline() which raises RuntimeError if called from within the hub's event loop (e.g., during signal handling).

(msg, f=sys.__stderr__)

Source from the content-addressed store, hash-verified

78
79
80def safe_say(msg, f=sys.__stderr__):
81 """
82 Uses the original (unpatched) os.write to avoid issues with eventlet/gevent
83 monkey-patching. When using eventlet>=0.37.0, the patched os.write calls
84 hubs.trampoline() which raises RuntimeError if called from within the
85 hub's event loop (e.g., during signal handling).
86 """
87 if hasattr(f, 'fileno') and f.fileno() is not None:
88 _original_os_write(f.fileno(), f'\n{msg}\n'.encode())
89
90
91class Worker(WorkController):

Callers 10

_handle_requestFunction · 0.85
during_soft_shutdownFunction · 0.85
on_cold_shutdownFunction · 0.85
on_SIGINTFunction · 0.85
cry_handlerFunction · 0.85
warn_on_HUP_handlerFunction · 0.85

Calls 1

encodeMethod · 0.45