This commit is contained in:
shenjack 2022-07-04 10:36:19 +08:00
parent bddc16a650
commit 8dd482988c
12 changed files with 99 additions and 36 deletions

35
DR.py
View File

@ -33,38 +33,37 @@ if __name__ == '__main__':
print(f'{os.path.split(os.path.split(os.path.realpath(__file__))[0])=}')
# 输出一遍大部分文件位置相关信息 以后可能会加到logs里
file_path = os.path.split(os.path.realpath(__file__))[0]
os.chdir(file_path)
sys.path.append(f'{file_path}/Difficult_Rocket')
sys.path.append(f'{file_path}/libs')
print(sys.path)
print(hi)
os.chdir(file_path) # 将运行路径切换到文件位置 防止bug
sys.path.append(f'{file_path}/Difficult_Rocket') # 添加local path
sys.path.append(f'{file_path}/libs') # 添加 libs path
print(sys.path) # 输出路径
print(hi) # hi
DEBUGGING = False
DEBUGGING = False # 是否在 DEBUG
from Difficult_Rocket.exception import TestError
from Difficult_Rocket.crash import crash
try:
start_time = time.perf_counter_ns()
import pyglet
pyglet.options["win32_gdi_font"] = True
start_time = time.perf_counter_ns() # 记录启动时间
import pyglet # 导入pyglet
from Difficult_Rocket import main
from libs.pyglet.gl import glClearColor
from libs.pyglet.gl import glClearColor # 调整背景颜色
glClearColor(0.5, 0.5, 0.5, 0)
game = main.Game()
game = main.Game() # 实例化一个游戏
print(time.perf_counter_ns() - start_time)
print(time.perf_counter_ns() - start_time) # 输出一下启动用时
cprofile = False
cprofile = False # 是否使用cprofile
if cprofile:
cProfile.run('game.start()', sort='calls')
cProfile.run('game.start()', sort='calls') # 使用 cprofile 启动
else:
game.start()
game.start() # 直接启动
if DEBUGGING:
raise TestError('debugging')
except Exception as exp:
print(error_format['error.happen'])
raise TestError('debugging') # debug 嘛试试crash
except Exception as exp: # 出毛病了
print(error_format['error.happen']) #
error = traceback.format_exc()
name = type(exp).__name__
if name in error_format:

View File

@ -13,7 +13,11 @@ gitee: @shenjackyuanjie
import threading
from typing import Union
from threading import Lock
from Difficult_Rocket import crash
from Difficult_Rocket.exception.threading import LockTimeOutError
class Threads(threading.Thread):
@ -21,3 +25,36 @@ class Threads(threading.Thread):
if crash.record_thread:
crash.all_thread.append(self)
super().run()
class ThreadLock:
def __init__(self, the_lock: Lock) -> None:
self.lock = the_lock
def __enter__(self, timeout: Union[float, int] = 1/60):
print(timeout)
self.lock.acquire(timeout=timeout)
if not self.lock.locked():
raise LockTimeOutError
def __exit__(self, exc_type, exc_val, exc_tb):
if (exc_type is None) and (exc_val is None) and (exc_tb is None):
# 没有出 bug
self.lock.release()
return None
else:
# 出 bug 了
self.lock.release()
return None
if __name__ == "__main__":
thread_lock = Lock()
test_lock = ThreadLock(thread_lock)
with test_lock:
...

View File

@ -16,8 +16,8 @@ import objprint
from typing import Union
from Difficult_Rocket.exception.language import *
from Difficult_Rocket.utils import tools
from Difficult_Rocket.exception.language import *
"""
@ -31,14 +31,18 @@ class Tr:
我不装了我就复刻tr
"""
def __init__(self):
self.frame = inspect.currentframe()
objprint.objprint(self.frame,
honor_existing=False,
depth=1)
self.config_regs = {}
objprint.objprint(self.frame.f_back,
honor_existing=False,
depth=1)
def add_config(self, configs: dict) -> None:
frame = inspect.currentframe()
self.config_regs[frame.f_back.f_code.co_filename] = configs
def __call__(self, *args, **kwargs):
frame = inspect.currentframe()
if frame.f_back.f_code.co_filename in self.config_regs:
...
else:
...
@ -94,12 +98,11 @@ class Lang:
raise TranslateKeyNotFound(f'{language}\'s language toml file not found')
def lang(self, *args) -> Union[int, str, list, dict]:
frame = inspect.currentframe()
print("调用当前log的函数名:", frame.f_back.f_code.co_name)
# print("调用当前log的文件名:", frame.f_back.f_code.co_filename)
objprint.objprint(frame.f_back.f_code,
honor_existing=False,
depth=2)
# frame = inspect.currentframe()
# # print("调用当前log的文件名:", frame.f_back.f_code.co_filename)
# objprint.objprint(frame.f_back.f_code,
# honor_existing=False,
# depth=2)
try:
结果 = self.翻译结果
for 选项 in args:

View File

@ -8,8 +8,8 @@ fonts_folder = "libs/fonts"
[window]
style = "None"
width = 1300
height = 931
width = 956
height = 569
visible = true
caption = "Difficult Rocket {version}"
resizable = true

Binary file not shown.

View File

@ -3,7 +3,7 @@ import threading
from time import strftime
from typing import Optional
from Difficult_Rocket.exception import
from Difficult_Rocket.exception.logger import LogFileLockTimeOutError
color_reset_suffix = "\033[0m"
@ -37,6 +37,7 @@ class LogFileCache:
def _log_file_time_write(self) -> None:
"""使用 threading.Timer 调用的定时写入日志文件的函数"""
if self.cache_count == 0:
return None
...

View File

@ -1,2 +1,3 @@
psutil
pillow
objprint

BIN
try/img.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

7
try/rust/Cargo.lock generated Normal file
View File

@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "rust"
version = "0.1.0"

12
try/rust/Cargo.toml Normal file
View File

@ -0,0 +1,12 @@
[package]
name = "rust"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
[[bin]]
name = "rust"
path = "main.rs"

3
try/rust/main.rs Normal file
View File

@ -0,0 +1,3 @@
fn main(){
println!("hello world");
}

View File

@ -1 +1 @@
viztracer --output_file ./logs/viz_result.json --open --tracer_entries 10000000 -O DR.py
viztracer --output_file ./logs/viz_result.json --open --tracer_entries 10000000 DR.py