mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 22:13:26 +00:00
python: Accept Optional[FrameType] in signal handlers.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
committed by
Tim Abbott
parent
7a9074ecfd
commit
702ce071f4
@@ -5,6 +5,7 @@ import subprocess
|
|||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
import types
|
import types
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
|
||||||
|
|
||||||
@@ -22,7 +23,7 @@ def check_worker_launch(run_dev: "subprocess.Popen[str]") -> bool:
|
|||||||
failed = False
|
failed = False
|
||||||
i = 0
|
i = 0
|
||||||
|
|
||||||
def on_timer(signum: int, frame: types.FrameType) -> None:
|
def on_timer(signum: int, frame: Optional[types.FrameType]) -> None:
|
||||||
nonlocal failed, i
|
nonlocal failed, i
|
||||||
sys.stdout.write(".")
|
sys.stdout.write(".")
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
|||||||
@@ -20,12 +20,13 @@ logger = logging.getLogger("zulip.debug")
|
|||||||
# (that link also points to code for an interactive remote debugger
|
# (that link also points to code for an interactive remote debugger
|
||||||
# setup, which we might want if we move Tornado to run in a daemon
|
# setup, which we might want if we move Tornado to run in a daemon
|
||||||
# rather than via screen).
|
# rather than via screen).
|
||||||
def interactive_debug(sig: int, frame: FrameType) -> None:
|
def interactive_debug(sig: int, frame: Optional[FrameType]) -> None:
|
||||||
"""Interrupt running process, and provide a python prompt for
|
"""Interrupt running process, and provide a python prompt for
|
||||||
interactive debugging."""
|
interactive debugging."""
|
||||||
d = {"_frame": frame} # Allow access to frame object.
|
d = {"_frame": frame} # Allow access to frame object.
|
||||||
d.update(frame.f_globals) # Unless shadowed by global
|
if frame is not None:
|
||||||
d.update(frame.f_locals)
|
d.update(frame.f_globals) # Unless shadowed by global
|
||||||
|
d.update(frame.f_locals)
|
||||||
|
|
||||||
message = "Signal received : entering python shell.\nTraceback:\n"
|
message = "Signal received : entering python shell.\nTraceback:\n"
|
||||||
message += "".join(traceback.format_stack(frame))
|
message += "".join(traceback.format_stack(frame))
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import threading
|
|||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
from types import FrameType
|
from types import FrameType
|
||||||
from typing import Any, Iterator, List
|
from typing import Any, Iterator, List, Optional
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core.management.base import BaseCommand, CommandError
|
from django.core.management.base import BaseCommand, CommandError
|
||||||
@@ -53,7 +53,7 @@ class Command(BaseCommand):
|
|||||||
logging.basicConfig()
|
logging.basicConfig()
|
||||||
logger = logging.getLogger("process_queue")
|
logger = logging.getLogger("process_queue")
|
||||||
|
|
||||||
def exit_with_three(signal: int, frame: FrameType) -> None:
|
def exit_with_three(signal: int, frame: Optional[FrameType]) -> None:
|
||||||
"""
|
"""
|
||||||
This process is watched by Django's autoreload, so exiting
|
This process is watched by Django's autoreload, so exiting
|
||||||
with status code 3 will cause this process to restart.
|
with status code 3 will cause this process to restart.
|
||||||
@@ -91,7 +91,7 @@ class Command(BaseCommand):
|
|||||||
queue_name = options["queue_name"]
|
queue_name = options["queue_name"]
|
||||||
worker_num = options["worker_num"]
|
worker_num = options["worker_num"]
|
||||||
|
|
||||||
def signal_handler(signal: int, frame: FrameType) -> None:
|
def signal_handler(signal: int, frame: Optional[FrameType]) -> None:
|
||||||
logger.info("Worker %d disconnecting from queue %s", worker_num, queue_name)
|
logger.info("Worker %d disconnecting from queue %s", worker_num, queue_name)
|
||||||
worker.stop()
|
worker.stop()
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|||||||
Reference in New Issue
Block a user