From b2aec1a51f7651672bd57da5ad0edfd1c8937125 Mon Sep 17 00:00:00 2001 From: Stephen Collinson Date: Tue, 20 Jun 2023 09:19:44 +0100 Subject: [PATCH 1/2] Cooperate with eventlet --- nameko_grpc/streams.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/nameko_grpc/streams.py b/nameko_grpc/streams.py index edf81b8..c8b9765 100644 --- a/nameko_grpc/streams.py +++ b/nameko_grpc/streams.py @@ -2,6 +2,8 @@ import struct from queue import Empty, Queue +from eventlet import greenthread + from nameko_grpc.compression import compress, decompress from nameko_grpc.errors import GrpcError from nameko_grpc.headers import HeaderManager @@ -201,6 +203,14 @@ def flush_queue_to_buffer(self): ) self.buffer.write(data) + # This while loop can lockup the main thread for a long time if we have a + # large queue of large messages to process. We need to yield to cooperate + # with eventlet greenthreads and this is the canonical way of doing so. + # Calling :func:`~greenthread.sleep` with *seconds* of 0 is the + # canonical way of expressing a cooperative yield + # TODO: Consider alternative solutions, ie breaking the flush into chunks + greenthread.sleep(0) + def serialize_message(self, message): return message.SerializeToString() From 2571e3d9136f840264840f4080539b0382ea4331 Mon Sep 17 00:00:00 2001 From: Stephen Collinson Date: Tue, 20 Jun 2023 09:42:37 +0100 Subject: [PATCH 2/2] fix build --- .github/workflows/ci.yaml | 14 +++++++------- tox.ini | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 312293d..b1fcb13 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -15,10 +15,10 @@ jobs: runs-on: ubuntu-latest steps: - name: checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: setup python - uses: actions/setup-python@v2 + uses: actions/setup-python@v4 with: python-version: 3.9 @@ -33,7 +33,7 @@ jobs: TOXENV: static test: - runs-on: ubuntu-latest + runs-on: ubuntu-20.04 strategy: matrix: python-version: @@ -44,10 +44,10 @@ jobs: steps: - name: checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: setup python - uses: actions/setup-python@v2 + uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} @@ -74,10 +74,10 @@ jobs: steps: - name: checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: setup python - uses: actions/setup-python@v2 + uses: actions/setup-python@v4 with: python-version: 3.9 diff --git a/tox.ini b/tox.ini index ff1fd3f..c7323f3 100644 --- a/tox.ini +++ b/tox.ini @@ -3,7 +3,7 @@ envlist = static, {py3.6,py3.7,py3.8,py3.9}-test skipsdist = True [testenv] -whitelist_externals = make +allowlist_externals = make commands = static: pip install pre-commit