Skip to content

Commit 14106f9

Browse files
authored
Disable SIGINT handling on GAE crons for metric collection (#4586)
This solves the following error: ``` signal only works in main thread of the main interpreter Traceback (most recent call last): File "/srv/handlers/base_handler.py", line 278, in dispatch_request return super().dispatch_request(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/layers/google.python.pip/pip/lib/python3.11/site-packages/flask/views.py", line 188, in dispatch_request return current_app.ensure_sync(meth)(**kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/srv/libs/handler.py", line 100, in wrapper with monitor.wrap_with_monitoring(): File "/layers/google.python.runtime/python/lib/python3.11/contextlib.py", line 137, in __enter__ return next(self.gen) ^^^^^^^^^^^^^^ File "/srv/clusterfuzz/_internal/metrics/monitor.py", line 148, in wrap_with_monitoring signal.signal(signal.SIGTERM, handle_sigterm) File "/layers/google.python.runtime/python/lib/python3.11/signal.py", line 58, in signal handler = _signal.signal(_enum_to_int(signalnum), _enum_to_int(handler)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ValueError: signal only works in main thread of the main interpreter ```
1 parent 738e024 commit 14106f9

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/clusterfuzz/_internal/metrics/monitor.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,10 @@ def wrap_with_monitoring():
145145
"""Wraps execution so we flush metrics on exit"""
146146
try:
147147
initialize()
148-
signal.signal(signal.SIGTERM, handle_sigterm)
148+
# Signals can only be handled in the main thread/interpreter
149+
# GAE crons do not satisfy this condition
150+
if not environment.is_running_on_app_engine():
151+
signal.signal(signal.SIGTERM, handle_sigterm)
149152
yield
150153
finally:
151154
stop()

0 commit comments

Comments
 (0)