-
-
Notifications
You must be signed in to change notification settings - Fork 318
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: correct typing on signal handler #664
Conversation
dramatiq/cli.py
Outdated
except OSError: # pragma: no cover | ||
if proc.exitcode is None: | ||
logger.warning("Failed to send %r to PID %d.", signum.name, proc.pid) | ||
logger.warning(f"Failed to send {signum.name} to PID {proc.pid}.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer to keep the format strings as they were since f-strings format eagerly, but loggers format lazily.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The linter should reject that anyway with W1203.
dramatiq/cli.py
Outdated
reload_process = signum == getattr(signal, "SIGHUP", None) | ||
if signum == signal.SIGINT: | ||
signum = signal.SIGTERM | ||
|
||
logger.info("Sending signal %r to subprocesses...", getattr(signum, "name", signum)) | ||
logger.info(f"Sending signal {signum.name} to subprocesses...") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto here.
the `signum` received in the signal handler is an `int`, not a `Signals` object. this leads to errors like so: ``` [2024-11-12 16:49:05,288] [PID 151] [MainThread] [dramatiq.ForkProcess(0)] [INFO] Stopping fork process... res = self._popen.wait(timeout) File "/usr/local/lib/python3.10/multiprocessing/popen_fork.py", line 43, in wait return self.poll(os.WNOHANG if timeout == 0.0 else 0) File "/usr/local/lib/python3.10/multiprocessing/popen_fork.py", line 27, in poll pid, sts = os.waitpid(self.pid, flag) File "/usr/local/lib/python3.10/site-packages/dramatiq/cli.py", line 579, in sighandler logger.info("Sending signal %r to subprocesses...", getattr(signum, "name", signum)) File "/usr/local/lib/python3.10/logging/__init__.py", line 1477, in info self._log(INFO, msg, args, **kwargs) File "/usr/local/lib/python3.10/logging/__init__.py", line 1624, in _log self.handle(record) File "/usr/local/lib/python3.10/logging/__init__.py", line 1634, in handle self.callHandlers(record) File "/usr/local/lib/python3.10/logging/__init__.py", line 1696, in callHandlers hdlr.handle(record) File "/usr/local/lib/python3.10/logging/__init__.py", line 966, in handle self.acquire() File "/usr/local/lib/python3.10/logging/__init__.py", line 917, in acquire self.lock.acquire() File "/usr/local/lib/python3.10/site-packages/dramatiq/cli.py", line 580, in sighandler stop_subprocesses(signum) File "/usr/local/lib/python3.10/site-packages/dramatiq/cli.py", line 571, in stop_subprocesses logger.warning("Failed to send %r to PID %d.", signum.name, proc.pid) AttributeError: 'int' object has no attribute 'name' ``` here, we correctly type the signal handler functions, and also convert the `int` to a `Signals` for consistency
addressed |
Forgot to say thanks. So, thanks! |
the
signum
received in the signal handler is anint
, not aSignals
object. this leads to errors like so:here, we correctly type the signal handler functions, and also convert the
int
to aSignals
for consistency