Skip to content

Commit

Permalink
Merge pull request #53 from stephenc-pace/fix/prevent-streaming-lockup
Browse files Browse the repository at this point in the history
Cooperate with eventlet
  • Loading branch information
timbu authored Sep 21, 2023
2 parents 39f53f0 + 2571e3d commit fcd1fac
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions nameko_grpc/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()

Expand Down

0 comments on commit fcd1fac

Please sign in to comment.