diff --git a/Difficult_Rocket.py b/Difficult_Rocket.py index c544efd..65389e3 100644 --- a/Difficult_Rocket.py +++ b/Difficult_Rocket.py @@ -31,8 +31,8 @@ if __name__ == '__main__': print(hi) try: - from Difficult_Rocket import main from Difficult_Rocket import crash + from Difficult_Rocket import main game = main.Game() game.start() diff --git a/Difficult_Rocket/api/Exp.py b/Difficult_Rocket/api/Exp.py index f5d0fa5..7541a30 100644 --- a/Difficult_Rocket/api/Exp.py +++ b/Difficult_Rocket/api/Exp.py @@ -11,6 +11,10 @@ github: @shenjackyuanjie gitee: @shenjackyuanjie """ +__all__ = ['TexturesError', + 'LanguageError', + 'TestError'] + class Error(Exception): @@ -38,3 +42,8 @@ class LanguageError(Error): def __str__(self): return '{}{}'.format(self.info, self.lang) + + +class TestError(Error): + """就像名字一样 用于测试的error""" + pass diff --git a/Difficult_Rocket/api/thread.py b/Difficult_Rocket/api/thread.py index aea09d5..19c99b2 100644 --- a/Difficult_Rocket/api/thread.py +++ b/Difficult_Rocket/api/thread.py @@ -19,5 +19,5 @@ from Difficult_Rocket import crash class Threads(threading.Thread): def run(self) -> None: if crash.record_thread: - crash.all_thread[self.name] = self + crash.all_thread.append(self) super(Threads, self).run() diff --git a/Difficult_Rocket/client.py b/Difficult_Rocket/client.py index 7025c50..8001efa 100644 --- a/Difficult_Rocket/client.py +++ b/Difficult_Rocket/client.py @@ -23,8 +23,10 @@ if __name__ == '__main__': # been start will not run this import pyglet from pyglet.window import key, mouse +from Difficult_Rocket.api.Exp import * from Difficult_Rocket.drag_sprite import DragSprite -from Difficult_Rocket.api import Exp, tools, config, new_thread +from Difficult_Rocket.crash import create_crash_report +from Difficult_Rocket.api import tools, config, new_thread class Client: @@ -204,8 +206,5 @@ class ClientWindow(pyglet.window.Window): config_file['window']['width'] = str(self.width) config_file['window']['height'] = str(self.height) config_file.write(open('configs/main.config', 'w', encoding='utf-8')) - # pyglet source code - self.has_exit = True - from pyglet import app - if app.event_loop.is_running: - self.close() + create_crash_report() + super(ClientWindow, self).on_close() diff --git a/Difficult_Rocket/crash.py b/Difficult_Rocket/crash.py index 3f372bd..44427a1 100644 --- a/Difficult_Rocket/crash.py +++ b/Difficult_Rocket/crash.py @@ -33,7 +33,7 @@ Thread_message = """## Thread info System_message = """## System info """ -all_thread = {threading.main_thread().name: threading.main_thread()} +all_thread = [threading.main_thread()] record_thread = True @@ -55,7 +55,10 @@ def markdown_line_handler(string: Optional[str or bool or int or float], code: b def create_crash_report(info: str = None) -> None: - crash_info = crash_info_handler(info) + if info: + crash_info = crash_info_handler(info) + else: + crash_info = crash_info_handler(traceback.format_exc()) if 'crash_report' not in os.listdir('./'): os.mkdir('./crash_report') date_time = time.strftime('%Y-%m-%d %H-%M-%S', time.gmtime(time.time())) @@ -65,9 +68,12 @@ def create_crash_report(info: str = None) -> None: crash_file.write(crash_info) crash_file.write(Thread_message) for thread in all_thread: - crash_file.write(markdown_line_handler(thread.name, code=True)) + thread: threading.Thread + crash_file.write(markdown_line_handler(f'{thread.name}', code=True)) + crash_file.write(markdown_line_handler(f'order: {all_thread.index(thread)}', level=2)) crash_file.write(markdown_line_handler(f'Ident: {thread.ident}', level=2)) crash_file.write(markdown_line_handler(f'Daemon: {thread.isDaemon()}', level=2)) + crash_file.write(markdown_line_handler(f'Running: {thread.is_alive()}', level=2)) crash_file.write(System_message)