| 130 | return self._closed |
| 131 | |
| 132 | def on_task_exception(self): |
| 133 | from ..output import toast, popup, put_error, PopupSize |
| 134 | from . import run_js |
| 135 | from . import info as session_info |
| 136 | |
| 137 | # log exception in server |
| 138 | logger.exception('Unhandled error in pywebio app') |
| 139 | |
| 140 | try: |
| 141 | toast_msg = "应用发生内部错误" if 'zh' in session_info.user_language else "An internal error occurred in the application" |
| 142 | if type(self).debug: |
| 143 | e_type, e_value, e_tb = sys.exc_info() |
| 144 | lines = traceback.format_exception(e_type, e_value, e_tb) |
| 145 | traceback_msg = ''.join(lines) |
| 146 | popup(title=toast_msg, content=put_error(traceback_msg), size=PopupSize.LARGE) |
| 147 | run_js("console.error(traceback_msg)", traceback_msg='Internal Server Error\n' + traceback_msg) |
| 148 | else: |
| 149 | toast(toast_msg, duration=1, color='error') |
| 150 | except Exception: |
| 151 | pass |
| 152 | |
| 153 | def register_callback(self, callback, **options): |
| 154 | """ 向Session注册一个回调函数,返回回调id |