Skip to content

Commit

Permalink
v0.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
lovemefan committed Aug 9, 2023
1 parent c3c2000 commit 7c13648
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 12 deletions.
4 changes: 3 additions & 1 deletion examples/simpleDemo/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from tzrpc import TZRPC_Server

server = TZRPC_Server(__name__)
server = TZRPC_Server(__name__, debug=False)


@server.register
Expand Down Expand Up @@ -47,8 +47,10 @@ def send_bool(_bool: bool):

@server.register
def send_python_obj(data):
print(data)
return data


if __name__ == "__main__":
server.run("localhost", 8000)

2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

setuptools.setup(
name="tzrpc",
version="0.0.1",
version="v0.0.2",
author="Lovemefan, Yunnan Key Laboratory of Artificial Intelligence, "
"Kunming University of Science and Technology, Kunming, Yunnan ",
author_email="[email protected]",
Expand Down
5 changes: 3 additions & 2 deletions tzrpc/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from tzrpc.proto.py.Number_pb2 import Double, Integer
from tzrpc.proto.py.Server_pb2_grpc import toObjectStub
from tzrpc.proto.py.String_pb2 import String
from tzrpc.utils.constant import MAX_MESSAGE_LENGTH
from tzrpc.utils.constant import MAX_MESSAGE_LENGTH, MAX_METADATA_SIZE
from tzrpc.utils.logger import get_logger
from tzrpc.utils.numpy_serialized import numpy2protobuf, protobuf2numpy

Expand Down Expand Up @@ -50,7 +50,8 @@ def __init__(self, server_address: str, debug=False):
self.server_address = server_address
self.channel = grpc.insecure_channel(server_address,
options=[('grpc.max_send_message_length', MAX_MESSAGE_LENGTH),
('grpc.max_receive_message_length', MAX_MESSAGE_LENGTH)]
('grpc.max_receive_message_length', MAX_MESSAGE_LENGTH),
('grpc.max_metadata_size', MAX_METADATA_SIZE)]
)

def register(self, func):
Expand Down
10 changes: 6 additions & 4 deletions tzrpc/server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from tzrpc.exceptions.exceptions import TZRPCException
from tzrpc.proto.py.Server_pb2_grpc import add_toObjectServicer_to_server
from tzrpc.server.base import tzrpcBase
from tzrpc.utils.constant import MAX_MESSAGE_LENGTH
from tzrpc.utils.constant import MAX_MESSAGE_LENGTH, MAX_METADATA_SIZE
from tzrpc.utils.logger import get_logger

logger = get_logger(to_std=True, stdout_level="INFO", save_log_file=False)
Expand All @@ -25,7 +25,8 @@
class TZRPC_Server(tzrpcBase):
def __init__(self, name, debug=False):
if debug:
logger.setLevel(logging.DEBUG)
get_logger(to_std=True, stdout_level="DEBUG" if debug else "INFO", save_log_file=False)\
.setLevel(logging.DEBUG)

super().__init__(name)

Expand Down Expand Up @@ -73,7 +74,7 @@ def run(
)

host, port = host or "127.0.0.1", port or 8000

get_logger(to_std=True, stdout_level="DEBUG" if debug else "INFO", save_log_file=False)
try:
self.is_running = True
self.is_stopping = False
Expand All @@ -87,7 +88,8 @@ def run(
logger.info(f"Tzrpc Server now listening {host}:{port}.")
server = grpc.server(futures.ThreadPoolExecutor(),
options=[('grpc.max_send_message_length', MAX_MESSAGE_LENGTH),
('grpc.max_receive_message_length', MAX_MESSAGE_LENGTH)]
('grpc.max_receive_message_length', MAX_MESSAGE_LENGTH),
('grpc.max_metadata_size', MAX_METADATA_SIZE)]
)
for servicer in servicers:
add_toObjectServicer_to_server(
Expand Down
2 changes: 2 additions & 0 deletions tzrpc/utils/constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@
}

MAX_MESSAGE_LENGTH = 500*1024*1024

MAX_METADATA_SIZE = 1024*16
9 changes: 5 additions & 4 deletions tzrpc/utils/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import os
import sys

logger_list = []
loggers_dict = {}
LEVEL = ("DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL")
DEFAULT_LOG_FILE_DIR = "~/.cache/tzrpc-log/"
LOCAL_DEFAULT_LOG_FILE_DIR = os.path.join(
Expand Down Expand Up @@ -69,9 +69,10 @@ def get_logger(logger_name: str = "tzrpc", **kwargs) -> logging.Logger:
Returns:
logger (logging.Logger): Logger.
"""

if logger_name in loggers_dict:
return loggers_dict[logger_name]
mf_logger = logging.getLogger(logger_name)
if logger_name in logger_list:
return mf_logger

save_log_file = kwargs.get("save_log_file", True)
stdout_level = kwargs.get("stdout_level", "INFO")
Expand Down Expand Up @@ -125,6 +126,6 @@ def get_logger(logger_name: str = "tzrpc", **kwargs) -> logging.Logger:
mf_logger.propagate = False
mf_logger.parent = None

logger_list.append(logger_name)
loggers_dict[logger_name] = mf_logger

return mf_logger

0 comments on commit 7c13648

Please sign in to comment.