Difficult-Rocket/Difficult_Rocket/server/__init__.py

41 lines
1.2 KiB
Python
Raw Normal View History

2022-03-22 21:18:04 +08:00
# -------------------------------
2021-09-08 23:38:34 +08:00
# Difficult Rocket
2023-01-20 14:08:12 +08:00
# Copyright © 2020-2023 by shenjackyuanjie 3695888@qq.com
2021-09-08 23:38:34 +08:00
# All rights reserved
# -------------------------------
2021-04-03 12:15:24 +08:00
import os
2023-04-05 11:53:40 +08:00
import time
2022-11-26 21:48:55 +08:00
# import multiprocessing
2021-08-24 22:31:52 +08:00
2022-06-14 20:52:03 +08:00
from Difficult_Rocket.utils import tools
from Difficult_Rocket.utils.translate import tr
from lib_not_dr import loggers
2021-01-21 15:05:29 +08:00
2021-09-05 00:50:05 +08:00
2024-05-26 14:01:48 +08:00
# TODO 改变服务端启动逻辑 0.6.0(划掉 0.8.0)(划掉 0.10.0)会写完的(
2021-02-22 21:32:13 +08:00
2021-01-21 15:05:29 +08:00
2021-08-24 22:31:52 +08:00
class Server:
2023-12-03 16:54:07 +08:00
def __init__(self, net_mode="local"):
2023-04-05 11:53:40 +08:00
start_time = time.time()
2023-12-24 16:09:54 +08:00
# log
2023-12-14 11:16:40 +08:00
self.logger = loggers.config.get_logger("server").set_tag("server")
2023-04-05 11:53:40 +08:00
self.logger.info(tr().server.setup.start())
2021-01-21 15:05:29 +08:00
# value
2022-11-26 21:48:55 +08:00
self.process_id = os.getpid()
# os.set
2023-12-03 16:54:07 +08:00
self.process_name = "server process"
2021-08-13 12:25:29 +08:00
# config
2023-12-03 16:54:07 +08:00
self.config = tools.load_file("config/main.toml")
2022-11-26 21:48:55 +08:00
# self.dev = Dev
# self.net_mode = net_mode
2023-04-05 11:53:40 +08:00
self.logger.info(tr().server.setup.use_time().format(time.time() - start_time))
2021-01-21 15:05:29 +08:00
def run(self):
2023-02-03 20:31:44 +08:00
self.logger.info(tr().server.os.pid_is().format(os.getpid(), os.getppid()))
2023-06-08 00:57:03 +08:00
def __repr__(self):
2023-12-03 16:54:07 +08:00
return f"<Server {self.process_name} {self.process_id}>"