Skip to content

Instantly share code, notes, and snippets.

from nebula3.gclient.net import ConnectionPool
from nebula3.Config import Config
# define a config
config = Config()
config.max_connection_pool_size = 10
# init connection pool
connection_pool = ConnectionPool()
# if the given servers are ok, return true, else return false
ok = connection_pool.init([('127.0.0.1', 9669)], config)
import logging
import os
import grpc
from protos import hello_pb2, hello_pb2_grpc
def get_filepath(filename, extension):
return f'{filename}{extension}'
def read_iterfile(filepath, chunk_size=1024):
def get_filepath(filename, extension):
return f'{filename}{extension}'
def run():
with grpc.insecure_channel('localhost:50051') as channel:
...
filename = 'test'
extension = '.jpg'
def read_iterfile(filepath, chunk_size=1024):
split_data = os.path.splitext(filepath)
filename = split_data[0]
extension = split_data[1]
metadata = hello_pb2.MetaData(filename=filename, extension=extension)
yield hello_pb2.UploadFileRequest(metadata=metadata)
with open(filepath, mode="rb") as f:
while True:
chunk = f.read(chunk_size)
from concurrent import futures
import logging
import os
import grpc
from protos import hello_pb2, hello_pb2_grpc
def get_filepath(filename, extension):
return f'{filename}{extension}'
class Greeter(hello_pb2_grpc.GreeterServicer):
def DownloadFile(self, request, context):
chunk_size = 1024
filepath = f'{request.filename}{request.extension}'
if os.path.exists(filepath):
with open(filepath, mode="rb") as f:
while True:
chunk = f.read(chunk_size)
if chunk:
def get_filepath(filename, extension):
return f'{filename}{extension}'
class Greeter(hello_pb2_grpc.GreeterServicer):
....
def UploadFile(self, request_iterator, context):
data = bytearray()
filepath = 'dummy'
syntax = "proto3";
// The greeting service definition.
service Greeter {
// Sends a greeting
rpc SayHello (HelloRequest) returns (StringResponse) {}
// Uploads a file
rpc UploadFile(stream UploadFileRequest) returns (StringResponse) {}
// Downloads a file
rpc DownloadFile(MetaData) returns (stream FileResponse) {}
import logging
import os
import grpc
from protos import hello_pb2, hello_pb2_grpc
def run():
with grpc.insecure_channel('localhost:50051') as channel:
stub = hello_pb2_grpc.GreeterStub(channel)
response = stub.SayHello(hello_pb2.HelloRequest(name='John Doe', age=30))
print("Greeter client received: " + response.message)
syntax = "proto3";
// The greeting service definition.
service Greeter {
// Sends a greeting
rpc SayHello (HelloRequest) returns (StringResponse) {}
}
message HelloRequest {
string name = 1;