reeeeee fix server crash?

This commit is contained in:
shenjack 2022-06-14 20:52:03 +08:00
parent 833be96cba
commit 232d074ce7
8 changed files with 197 additions and 13 deletions

View File

@ -19,9 +19,10 @@ if __name__ == '__main__': # been start will not run this
sys.path.append('/bin/libs') sys.path.append('/bin/libs')
sys.path.append('/bin') sys.path.append('/bin')
from utils import tools from Difficult_Rocket.utils import tools
from Difficult_Rocket.utils.translate import tr
from Difficult_Rocket.api.delivery import Delivery from Difficult_Rocket.api.delivery import Delivery
from utils.new_thread import new_thread from Difficult_Rocket.utils.new_thread import new_thread
# TODO 改变服务端启动逻辑 0.6.0会写完的( # TODO 改变服务端启动逻辑 0.6.0会写完的(
@ -40,10 +41,7 @@ class Server:
self.config = tools.load_file('configs/main.config') self.config = tools.load_file('configs/main.config')
self.dev = Dev self.dev = Dev
self.net_mode = net_mode self.net_mode = net_mode
# lang self.logger.info(tr.lang('server', 'setup.done'))
self.lang = tools.load_file('configs/lang/%s.json5' % self.config['runtime']['language'], 'server')
self.logger.info('%s' % self.lang['setup.done'])
@new_thread('Server')
def run(self): def run(self):
self.logger.info(self.lang['os.pid_is'].format(os.getpid(), os.getppid())) self.logger.info(tr.lang('server', 'os.pid_is').format(os.getpid(), os.getppid()))

View File

@ -39,6 +39,7 @@ class Lang:
self.语言 = language self.语言 = language
self.翻译结果 = tools.load_file(f'configs/lang/{language}.toml') self.翻译结果 = tools.load_file(f'configs/lang/{language}.toml')
self.默认翻译 = tools.load_file('configs/lang/zh-CN.toml') self.默认翻译 = tools.load_file('configs/lang/zh-CN.toml')
self.直接返回原始数据 = True
def __str__(self) -> str: def __str__(self) -> str:
return self.语言 return self.语言
@ -58,6 +59,8 @@ class Lang:
self.翻译结果 = tools.load_file(f'configs/lang/{value}.toml') self.翻译结果 = tools.load_file(f'configs/lang/{value}.toml')
self.语言 = value self.语言 = value
except FileNotFoundError: except FileNotFoundError:
if self.直接返回原始数据:
return None
raise LanguageError(f'{value}\'s language toml file not found') raise LanguageError(f'{value}\'s language toml file not found')
else: else:
raise NotImplementedError raise NotImplementedError
@ -82,6 +85,8 @@ class Lang:
结果 = 结果[选项] 结果 = 结果[选项]
return 结果 return 结果
except KeyError: except KeyError:
if self.直接返回原始数据:
return args
raise LanguageError(f'there\'s no key {args} in both {self.语言} and zh-CN') raise LanguageError(f'there\'s no key {args} in both {self.语言} and zh-CN')
def 翻译(self, *args) -> Union[int, str, list, dict]: def 翻译(self, *args) -> Union[int, str, list, dict]:

View File

@ -0,0 +1,170 @@
from time import strftime
__all__ = [
"Log"
]
class Log:
"""
参数:\n
Shell -- 是否输出消息 -> 控制台 (DefaultTrue) | Boolean\n
LogFile -- 是否输出消息 -> 文件 (Default: False) | Boolean\n
FileName [已使用格式化时间] -- 输出文件名 LogFile=True 时此参数有效Default%Y-%m-%d_%H-%M.log | String\n
FileName 请注意符合对应操作系统的文件命名要求\n
"""
def __init__(self,
Shell=True,
LogFile=False,
FileName="%Y-%m-%d_%H-%M.log"
):
self.Shell = Shell
self.LogFile = LogFile
self.FileName = FileName
def info(self, Message):
if self.Shell:
Console.info(Message)
if self.LogFile:
file = File(FileName=self.FileName)
file.info(Message)
def warning(self, Message):
if self.Shell:
Console.warning(Message)
if self.LogFile:
file = File(FileName=self.FileName)
file.warning(Message)
def error(self, Message):
if self.Shell:
Console.error(Message)
if self.LogFile:
file = File(FileName=self.FileName)
file.error(Message)
def fatal(self, Message):
if self.Shell:
Console.fatal(Message)
if self.LogFile:
file = File(FileName=self.FileName)
file.fatal(Message)
def debug(self, Message):
if self.Shell:
Console.debug(Message)
if self.LogFile:
file = File(FileName=self.FileName)
file.debug(Message)
class Console:
"""
This class can output colored messages to Shell.
"""
from colorama import init
sColorSuffix = "\033[0m"
init(autoreset=True)
@staticmethod
def info(Message):
print(
strftime(
f"[%H:%M:%S] [\033[32mINFO{Console.sColorSuffix}]: {Message}"
)
)
@staticmethod
def warning(Message):
print(
strftime(
f"[%H:%M:%S] [\033[33mWARN{Console.sColorSuffix}]: {Message}"
)
)
@staticmethod
def error(Message):
print(
strftime(
f"[%H:%M:%S] [\033[31mERROR{Console.sColorSuffix}]: {Message}"
)
)
@staticmethod
def fatal(Message):
print(
strftime(
f"[%H:%M:%S] [\033[1;31;47mFATAL{Console.sColorSuffix}]: {Message}"
)
)
@staticmethod
def debug(Message):
print(
strftime(
f"[%H:%M:%S] [\033[34mDEBUG{Console.sColorSuffix}]: {Message}"
)
)
class File:
"""
This class can output messages to file.
"""
def __init__(self, FileName):
self.File = open(strftime(FileName), "a", encoding="utf-8")
def __del__(self):
self.File.close()
def info(self, Message):
self.File.write(
strftime(
f"[%H:%M:%S] [INFO]: {Message}\n"
)
)
def warning(self, Message):
self.File.write(
strftime(
f"[%H:%M:%S] [WARN]: {Message}\n"
)
)
def error(self, Message):
self.File.write(
strftime(
f"[%H:%M:%S] [ERROR]: {Message}\n"
)
)
def fatal(self, Message):
self.File.write(
strftime(
f"[%H:%M:%S] [FATAL]: {Message}\n"
)
)
def debug(self, Message):
self.File.write(
strftime(
f"[%H:%M:%S] [DEBUG]: {Message}\n"
)
)
if __name__ == '__main__':
from time import sleep
logger = Log(LogFile=True)
logger.info("这是一条正常消息")
sleep(1)
logger.warning("这是一条警告消息")
sleep(2)
logger.error("这是一条错误消息")
sleep(3)
logger.fatal("这是一条致命错误消息")
sleep(4)
logger.debug("这是一条调试消息")

Binary file not shown.

1
try/c/compile.ps1 Normal file
View File

@ -0,0 +1 @@
gcc -Wall -Werror -O3 -o feb_speed.exe .\feb_speed.c

View File

@ -5,18 +5,28 @@
int64_t feb(int64_t* cache, int32_t count) int64_t feb(int64_t* cache, int32_t count)
{ {
if(count == 1 + count == 0){ if ((count == 1) + (count == 0)) {
return 1; return 1;
}; };
return count; if (cache[count] == 0) {
return cache[count];
};
cache[count] = feb(cache, --count) + feb(cache, --count);
return cache[count];
}; };
int main() int main()
{ {
int64_t count; int32_t count;
printf("嘿!给我个数字,别太大!");
scanf("%d", &count); scanf("%d", &count);
printf("将要输出第%d个feb", count); printf("将要输出第 %d 个feb\n", count);
int64_t* cache[count]; int64_t* cache;
cache = calloc(count, sizeof(int64_t));
int64_t result = feb(cache, count);
printf("%d", result);
return 0; return 0;
} }

Binary file not shown.

Binary file not shown.