How do I specify server options?

2024/9/25 21:29:55

I'm trying to run gRPC server in Python. I found a way to do it like this:

import grpc
from concurrent import futuresserver = grpc.server(futures.ThreadPoolExecutor(max_workers=100))
... # add my grpc servicer to server
server.add_insecure_port('[::]:50051')
server.start()

I need to add some options to the server like max_send_message_length, max_receive_message_length, etc. There is an options argument in grpc.server(...), but I can't figure out how to use it.

server = grpc.server(futures.ThreadPoolExecutor(max_workers=100), options=[???])

From gRPC documentation:

options – An optional list of key-value pairs (channel args in gRPC runtime) to configure the channel.

How do I create these options? Are they string-string pairs?

I'm new to Python and gRPC, though.

Answer

You can find an example in this github issue: https://github.com/grpc/grpc/issues/11299

For 30mb max message length use:

options = [('grpc.max_message_length', 30 * 1024 * 1024)]

https://en.xdnf.cn/q/71534.html

Related Q&A

How to find collocations in text, python

How do you find collocations in text? A collocation is a sequence of words that occurs together unusually often. python has built-in func bigrams that returns word pairs. >>> bigrams([more, i…

How to set size of a Gtk Image in Python

How can I set the width and height of a GTK Image in Python 3.

Numpy Vectorized Function Over Successive 2d Slices

I have a 3D numpy array. I would like to form a new 3d array by executing a function on successive 2d slices along an axis, and stacking the resulting slices together. Clearly there are many ways to do…

MySQL and Python Select Statement Issues

Thanks for taking the time to read this. Its going to be a long post to explain the problem. I havent been able to find an answer in all the usual sources.Problem: I am having an issue with using the …

How to pass variable in url to Django List View

I have a Django generic List View that I want to filter based on the value entered into the URL. For example, when someone enters mysite.com/defaults/41 I want the view to filter all of the values mat…

Django Select Option selected issue

I tried to follow some examples on stackoverflow for option selected in select list but still, I could not get it work.This is my code snippet<select name="topic_id" style="width:90%&…

reading tab-delimited data without header in pandas

Im having trouble using pandas to open tab-delimited data without headers.My test data (actually contains 200 lines, of which I am showing the first 10):Tag19184 CTAAC hffef 1 a 36 - chr1…

Python Try/Except with multiple except blocks

try:raise KeyError() except KeyError:print "Caught KeyError"raise Exception() except Exception:print "Caught Exception"As expected, raising Exception() on the 5th line isnt caught i…

How to install trax, jax, jaxlib on M1 Mac on macOS 12?

trax New to trax, Im trying to run it locally (macOS 12.1, Apple Silicon ARM M1 processor, 8GB RAM, Anaconda), but Im running into some issues. In an environment with python 3.8.5, I installed trax run…

How do I match a word in a text file using python?

I want to search and match a particular word in a text file.with open(wordlist.txt, r) as searchfile:for line in searchfile:if word in line:print lineThis code returns even the words that contain subst…