diff --git a/CHANGELOG.md b/CHANGELOG.md index f507f1bd..0a35b004 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Set upper bound for version of setuptools (PR #342). +- Reduce idle CPU usage in `ConnectionPool` while waiting for + queued requests (PR #336). ## 1.2.0 - 2024-03-27 diff --git a/tarantool/connection_pool.py b/tarantool/connection_pool.py index f1e675b3..1734402a 100644 --- a/tarantool/connection_pool.py +++ b/tarantool/connection_pool.py @@ -660,8 +660,12 @@ def _request_process_loop(self, key, unit, last_refresh): """ while unit.request_processing_enabled: - if not unit.input_queue.empty(): - task = unit.input_queue.get() + try: + task = unit.input_queue.get(timeout=self.refresh_delay) + except queue.Empty: + task = None + + if task: method = getattr(Connection, task.method_name) try: resp = method(unit.conn, *task.args, **task.kwargs)