You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
My program uses custom signal handlers to terminate the running sanic application and perform other cleanup steps. In earlier sanic versions it worked by running the application with register_sys_signals=False parameter. In the current version it is not working anymore, because the custom signal handler is overwritten by SIG_IGN upon application startup. See:
According to git blame the behavior changed with this commit: 4499d2c
Code snippet
import os, signal, threading, time
import sanic
def myhandler(signum, frameno):
print('RECEIVED SIGNAL', signum)
signal.signal(signal.SIGTERM, myhandler)
def periodic_kill():
for i in range(4):
print('SENDING SIGNAL', signal.SIGTERM)
os.kill(os.getpid(), signal.SIGTERM)
time.sleep(1)
os.kill(os.getpid(), signal.SIGKILL)
t = threading.Thread(target=periodic_kill, daemon=True)
t.start()
time.sleep(0.5)
app = sanic.Sanic('example')
app.run(host='localhost', port=8765, register_sys_signals=False, single_process=True)
Expected Behavior
Expected output:
SENDING SIGNAL 15
RECEIVED SIGNAL 15
# sanic startup messages
SENDING SIGNAL 15
RECEIVED SIGNAL 15
SENDING SIGNAL 15
RECEIVED SIGNAL 15
SENDING SIGNAL 15
RECEIVED SIGNAL 15
Killed
Actual output: the RECIEVED SIGNAL 15 messages do not appear after sanic startup.
How do you run Sanic?
As a module
Operating System
Linux
Sanic Version
Sanic 23.12.1; Routing 23.12.0
Additional context
No response
The text was updated successfully, but these errors were encountered:
To have different behavior for SIGINT and SIGTERM. I have a complicated application with multiple workers (not sanic workers), each starting its own sanic instance. There is an orchestrator component that manages the workers. The application should terminate nicely when CTRL-C is pressed. The shut-down process is managed by the orchestrator, workers should not terminate themselves on SIGINT.
What is the reason behind forcefully setting SIG_IGN?
Is there an existing issue for this?
Describe the bug
My program uses custom signal handlers to terminate the running sanic application and perform other cleanup steps. In earlier sanic versions it worked by running the application with
register_sys_signals=False
parameter. In the current version it is not working anymore, because the custom signal handler is overwritten bySIG_IGN
upon application startup. See:sanic/sanic/server/runners.py
Lines 159 to 177 in f8e0a72
According to git blame the behavior changed with this commit: 4499d2c
Code snippet
Expected Behavior
Expected output:
Actual output: the
RECIEVED SIGNAL 15
messages do not appear after sanic startup.How do you run Sanic?
As a module
Operating System
Linux
Sanic Version
Sanic 23.12.1; Routing 23.12.0
Additional context
No response
The text was updated successfully, but these errors were encountered: