update DR&DR-start.py #39

Merged
erduotong merged 2 commits from main into main 2023-07-11 18:57:03 +08:00
2 changed files with 46 additions and 25 deletions

View File

@ -3,45 +3,69 @@
# Copyright © 2020-2023 by shenjackyuanjie 3695888@qq.com # Copyright © 2020-2023 by shenjackyuanjie 3695888@qq.com
# All rights reserved # All rights reserved
# ------------------------------- # -------------------------------
import os import os
import sys import sys
import time import time
import traceback
import threading
from pathlib import Path
hi = """Difficult Rocket is writen by shenjackyuanjie hi = """Difficult Rocket is writen by shenjackyuanjie
email: 3695888@qq.com or shyj3695888@163.com email: 3695888@qq.com or shyj3695888@163.com
QQ: 3695888""" QQ: 3695888"""
errors = {
'TestError': '游戏正在调试中,某处引发了一个 TestError不是bug造成的原因',
'AssertionError': '游戏的某处检查未通过情报告issue',
'error.unknown': '游戏报错了现在输出报错信息请报告issue',
'error.happen': '游戏出现了一个报错!正在处理'
}
def print_path() -> None: def print_path() -> None:
print(f'{__file__=}') print(f'{__file__=}')
print(f'{sys.path=}') print(f'{sys.path=}')
print(f'{sys.path[0]=}') print(f'{sys.path[0]=}')
print(f'{sys.argv[0]=}') print(f'{sys.argv[0]=}')
print(f'{os.getcwd()=}') print(f'{Path.cwd()=}')
print(f'{os.path.abspath(__file__)=}') print(f'{Path(__file__).absolute()=}')
print(f'{os.path.realpath(__file__)=}')
print(f'{os.path.split(os.path.split(os.path.realpath(__file__))[0])=}')
# 输出一遍大部分文件位置相关信息 以后可能会加到logs里
def modify_path() -> None: def modify_path() -> None:
file_path = os.path.split(os.path.realpath(__file__))[0] os.chdir(Path(__file__)) # 将运行路径切换到文件位置 防止bug
os.chdir(file_path) # 将运行路径切换到文件位置 防止bug sys.path.append(f'./Difficult_Rocket') # 添加local path
sys.path.append(f'{file_path}/Difficult_Rocket') # 添加local path sys.path.append(f'./libs') # 添加 libs path
sys.path.append(f'{file_path}/libs') # 添加 libs path
def start(start_time_ns: int) -> None:
from Difficult_Rocket import crash, DR_status
from Difficult_Rocket.runtime import DR_runtime
from Difficult_Rocket.exception import TestError
DR_runtime.start_time_ns = start_time_ns
try:
from Difficult_Rocket import main
main_game = main.Game()
main_game.start()
if DR_status.crash_report_test:
raise TestError('debug crash test')
except:
trace = traceback.format_exc()
crash.create_crash_report(trace)
crash.write_info_to_cache(sys.stdout)
print(crash.all_thread)
print(crash.all_process)
for a_thread in threading.enumerate():
print(a_thread)
if a_thread.is_alive() and a_thread != threading.current_thread() and a_thread != threading.main_thread():
a_thread.join(2) # wait for 2 sec
import pyglet
pyglet.app.exit() # make sure that pyglet has stopped
def main() -> int:
print(hi, f"\n{time.ctime()}") # hi
# 记录启动信息
start_time_ns = time.time_ns()
print_path()
modify_path()
start(start_time_ns)
return 0
if __name__ == '__main__': if __name__ == '__main__':
print(hi,f"\n{time.ctime()}") # hi sys.exit(main())
# 记录启动信息
start_time_ns = time.time_ns()
start_time_perf_ns = time.perf_counter_ns()
print_path()
modify_path()

3
DR.py
View File

@ -62,9 +62,6 @@ def main() -> int:
from Difficult_Rocket.runtime import DR_runtime from Difficult_Rocket.runtime import DR_runtime
DR_runtime.start_time_ns = start_time_ns DR_runtime.start_time_ns = start_time_ns
# from 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_perf_ns, (time.perf_counter_ns() - start_time_perf_ns) / (10 ** 9), 'start') # 输出一下启动用时 print(time.perf_counter_ns() - start_time_perf_ns, (time.perf_counter_ns() - start_time_perf_ns) / (10 ** 9), 'start') # 输出一下启动用时