billiard
billiard copied to clipboard
return in finally can swallow exceptions
In three places in your codebase, you have a return statement in a finally block, which would swallow any in-flight exception:
https://github.com/celery/billiard/blob/366ac5f9a708a64fc48f94da465189f9309288ab/billiard/connection.py#L349 https://github.com/celery/billiard/blob/366ac5f9a708a64fc48f94da465189f9309288ab/billiard/connection.py#L351 https://github.com/celery/billiard/blob/366ac5f9a708a64fc48f94da465189f9309288ab/billiard/pool.py#L1856
This means that if a BaseException (such as KeyboardInterrupt) is raised from the try body, or any exception is raised from an except: clause, it will not propagate on as expected.
See also https://docs.python.org/3/tutorial/errors.html#defining-clean-up-actions.
thanks for the report! it is a very old code base, we will try to clean it asap
I upgraded my app to use the new Python 3.14 and I see the following messages in the terminal when start my Django app in dev mode:
/.venv/lib/python3.14/site-packages/billiard/pool.py:1856: SyntaxWarning: 'return' in a 'finally' block
return self._send_ack(
/.venv/lib/python3.14/site-packages/billiard/connection.py:349: SyntaxWarning: 'return' in a 'finally' block
return f
/.venv/lib/python3.14/site-packages/billiard/connection.py:351: SyntaxWarning: 'return' in a 'finally' block
return self._get_more_data(ov, maxsize)
This issue can also be observed when launching celery as a task runner for flask.
/code/.venv/lib/python3.14/site-packages/billiard/pool.py:1856: SyntaxWarning: 'return' in a 'finally' block
return self._send_ack(
/code/.venv/lib/python3.14/site-packages/billiard/connection.py:349: SyntaxWarning: 'return' in a 'finally' block
return f
/code/.venv/lib/python3.14/site-packages/billiard/connection.py:351: SyntaxWarning: 'return' in a 'finally' block
return self._get_more_data(ov, maxsize)
/code/.venv/lib/python3.14/site-packages/celery/concurrency/asynpool.py:409: SyntaxWarning: 'return' in a 'finally' block
return remove(fd)
-------------- celery@2950dba2997b v5.5.3 (immunity)
--- ***** -----
-- ******* ---- Linux-6.6.87.2-microsoft-standard-WSL2-x86_64-with-glibc2.41 2025-10-15 04:24:36
- *** --- * ---
- ** ---------- [config]
- ** ---------- .> app: factory:0x751fc3ddd400
- ** ---------- .> transport: redis://redis:6379/0
- ** ---------- .> results: redis://redis:6379/0
- *** --- * --- .> concurrency: 20 (prefork)
-- ******* ---- .> task events: OFF (enable -E to monitor tasks in this worker)
--- ***** -----
-------------- [queues]
.> celery exchange=celery(direct) key=celery
@auvipy do you need help to apply the changes?
I just made #438 to make this compatible with Python 3.14 (which disapproves of 'return' inside of 'finally' blocks). I guess that should also fix this issue?