프로젝트

일반

사용자정보

개정판 f5c52575

IDf5c52575b6b177ef3a656269ec84b19e2f6d2982
상위 5fb1ee2f
하위 3fa30e19

백흠경이(가) 5년 이상 전에 추가함

revised issue #1007: 프로그램이 비 정상 종료시 에러 로그를 남긴다

Change-Id: Ia524bec7b79c5a1e20b0d6643928aabb115657c7

차이점 보기:

DTI_PID/DTI_PID/App.py
1 1
# coding: utf-8
2
"""
3
    This is application module
4
"""
2
""" This is application module """
5 3
import sys
6 4
import os
7 5

  
......
94 92
    def mainWnd():
95 93
        return QtWidgets.qApp._mainWnd
96 94

  
97
def handle_unhandled_exception(exc_type, exc_value, exc_traceback):
98
    """Handler for unhandled exceptions that will write to the logs"""
99
    if issubclass(exc_type, KeyboardInterrupt):
100
        # call the default excepthook saved at __excepthook__
101
        sys.__excepthook__(exc_type, exc_value, exc_traceback)
102
        return
103
    logger.critical("Unhandled exception", exc_info=(exc_type, exc_value, exc_traceback))
95
def f():
96
    return 1/0
104 97

  
105 98
'''
106 99
    @history    18.04.23    Jeongwoo    Change method to execute ProjectDialog(dlg.exec_()→dlg.showDialog())
107 100
'''
108 101
if __name__ == '__main__':
109
    import logging
110 102
    import cv2
111 103
    from License import QLicenseDialog
112 104
    from ProjectDialog import Ui_Dialog
113 105
    from MainWindow import MainWindow
106
    from ExceptionHandler import QExceptionHandler
107

  
108
    app = App(sys.argv) 
114 109

  
115 110
    """ log for unhandled exception """
116
    log_path = os.path.join(os.getenv('ALLUSERSPROFILE'), 'Digital PID', 'id2.log')
117
    logger = logging.getLogger(__name__)
118
    logging.basicConfig(filename=log_path , filemode='w', level=logging.DEBUG)
119
    sys.execpthook = handle_unhandled_exception
111
    exceptionHandler = QExceptionHandler()
112
    sys._excepthook = sys.excepthook
113
    sys.excepthook = exceptionHandler.handler
120 114

  
121
    app = App(sys.argv) 
122 115
    """
123 116
    try:
124 117
        import qtmodern.styles
......
127 120
    else:
128 121
        qtmodern.styles.darkorange(app)
129 122
    """
130
    try:
131
        if True == QLicenseDialog.check_license_key():
132
            dlg = Ui_Dialog()
133
            selectedProject = dlg.showDialog()
134
            if selectedProject is not None:
135
                AppDocData.instance().setCurrentProject(selectedProject)
136
                app._mainWnd = MainWindow.instance()
137
                app._mainWnd.show()
138
                sys.exit(app.exec_())
139
    except Exception as ex:
140
         print('에러가 발생했습니다.\n', ex)
141
    except:
142
        ex = sys.exc_info()[0]
143
        print('에러가 발생했습니다.\n', ex)
123
    if True == QLicenseDialog.check_license_key():
124
        dlg = Ui_Dialog()
125
        selectedProject = dlg.showDialog()
126
        if selectedProject is not None:
127
            AppDocData.instance().setCurrentProject(selectedProject)
128
            app._mainWnd = MainWindow.instance()
129
            app._mainWnd.show()
130
            sys.exit(app.exec_())
DTI_PID/DTI_PID/ExceptionHandler.py
1
# coding: utf-8
2
""" This is exception handler module """
3

  
4
import sys
5
import os
6

  
7
from PyQt5.QtCore import *
8
from PyQt5.QtGui import *
9
from PyQt5.QtWidgets import *
10
from PyQt5.QtXml import *
11
from PyQt5.QtSvg import *
12
from PyQt5 import QtWidgets
13
import logging
14

  
15
class QExceptionHandler(QObject):
16
    """ This is exception handler class """
17

  
18
    errorSignal = pyqtSignal()
19

  
20
    def __init__(self):
21
        super(QExceptionHandler, self).__init__()
22

  
23
        self.log_path = os.path.join(os.getenv('ALLUSERSPROFILE'), 'Digital PID', 'id2.log')
24
        self.logger = logging.getLogger(__name__)
25
        logging.basicConfig(filename=self.log_path , filemode='w', level=logging.CRITICAL)
26

  
27
    def handler(self, exctype, value, traceback):
28
        """ log exception, file namd and line number """
29

  
30
        message = 'error occured({}) in {}:{}'.format(value, traceback.tb_frame.f_code.co_filename, traceback.tb_lineno)
31
        self.errorSignal.emit()
32
        self.logger.critical('Unhandled exception: {}'.format(message))
DTI_PID/DTI_PID/LineNoTracer.py
380 380
                    lineMatches = [x for x in self._lines if (x.owner is None or x.owner == start.owner) and (x not in visited) and obj.is_connected(x)]
381 381

  
382 382
                    if len(lineMatches) > 1: # choose one if connected lines are more than 2
383
                        matches = [x for x in [visited[0], visited[-1]] if obj.is_connected(x)]
383
                        matches = [x for x in visited if obj.is_connected(x)]
384 384
                        if matches:
385 385
                            next_connected = [x for x in lineMatches if obj.next_connected(x, matches[0])]
386 386
                            if next_connected:

내보내기 Unified diff

클립보드 이미지 추가 (최대 크기: 500 MB)