Mentions légales du service

Skip to content
Snippets Groups Projects
Commit d6df9635 authored by BIGAUD Nathan's avatar BIGAUD Nathan
Browse files

Server template scripts

parent 9eb02596
No related branches found
No related tags found
1 merge request!46Draft: Docker deploy
import csv
import os
import sys
import time
from concurrent import futures
import fire
import grpc
sys.path.append("./comms")
from comms import message_pb2, message_pb2_grpc
FILEDIR = os.path.dirname(__file__)
class Servicer(message_pb2_grpc.BasicMessageServicer):
def __init__(self):
self.responses = []
def SendMessage(self, request, context):
self.responses.append(request.res)
return message_pb2.BasicReply(ok=f"{request.res}")
def serve(clients: int = 5, port: str = "8000"):
# Set up
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
servicer = Servicer()
message_pb2_grpc.add_BasicMessageServicer_to_server(servicer, server)
server.add_insecure_port("[::]:" + port)
# Start server
server.start()
print("Server started, listening on " + port)
# Monitoring results
target_sum = sum((i**2 for i in range(clients)))
while sum(servicer.responses) < target_sum:
print(f"Current sum:{sum(servicer.responses)}, goal:{target_sum}")
time.sleep(2)
# When target sum is reached
if sum(servicer.responses) == target_sum:
with open("responses.csv", "w", encoding="UTF8") as f:
writer = csv.writer(f)
writer.writerow(servicer.responses)
print("Target reached, exchange closed")
server.stop(None)
else:
raise (ValueError("Unexpected results from clients"))
if __name__ == "__main__":
fire.Fire(serve)
# Set env var
echo "Setting environment variables"
set -o allexport
source .env
set +o allexport
echo "NBCLIENTS set to $NBCLIENTS"
# Run the client server python script
python -u run.py --clients $NBCLIENTS
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment