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
When running a taskiq worker that spawns subprocesses, KeyboardInterrupt exceptions are not being caught and handled as expected. This results in an unhandled exception traceback being printed when attempting to gracefully shut down the worker.
Steps to Reproduce
Set up a taskiq worker that spawns subprocesses in its tasks
Run the worker
Send a SIGINT or SIGTERM to the worker process (e.g., by pressing Ctrl+C)
Expected Behavior
The worker should catch the KeyboardInterrupt, log a warning message, and proceed to shut down the broker gracefully.
Actual Behavior
An unhandled KeyboardInterrupt exception is raised, and a traceback is printed:
File "taskiq/receiver/receiver.py", line 271, in run_task
returned = await target_future
File "myapp/tasks.py", line 94, in process_call
spawn_bot(
File "myapp/bot_spawner.py", line 115, in spawn_bot
subprocess.check_call(
File "subprocess.py", line 408, in check_call
retcode = call(*popenargs, **kwargs)
File "subprocess.py", line 391, in call
return p.wait(timeout=timeout)
File "subprocess.py", line 1264, in wait
return self._wait(timeout=timeout)
File "subprocess.py", line 2053, in _wait
(pid, sts) = self._try_wait(0)
File "subprocess.py", line 2011, in _try_wait
(pid, sts) = os.waitpid(self.pid, wait_flags)
File "taskiq/cli/worker/run.py", line 107, in interrupt_handler
raise KeyboardInterrupt
The issue seems to occur because the KeyboardInterrupt is being raised while waiting for a subprocess to complete. The exception is propagating through the async call stack before it can be caught by the main try-except block in the start_listen function.
The text was updated successfully, but these errors were encountered:
Description
When running a taskiq worker that spawns subprocesses, KeyboardInterrupt exceptions are not being caught and handled as expected. This results in an unhandled exception traceback being printed when attempting to gracefully shut down the worker.
Steps to Reproduce
Expected Behavior
The worker should catch the KeyboardInterrupt, log a warning message, and proceed to shut down the broker gracefully.
Actual Behavior
An unhandled KeyboardInterrupt exception is raised, and a traceback is printed:
Environment
taskiq worker myapp.worker:broker myapp.tasks --workers=4 --max-threadpool-threads=1 --max-async-tasks=1 --ack-type=when_executed --wait-tasks-timeout=600 --shutdown-timeout=630 --max-tasks-per-child=1000
taskiq_redis.ListQueueBroker
Additional Context
The issue seems to occur because the KeyboardInterrupt is being raised while waiting for a subprocess to complete. The exception is propagating through the async call stack before it can be caught by the main try-except block in the
start_listen
function.The text was updated successfully, but these errors were encountered: