Print python exception tracebacks
This commit is contained in:
parent
001d6eff71
commit
7a5a1fc650
@ -2,14 +2,15 @@ import asyncio
|
||||
import logging as log
|
||||
import signal
|
||||
import sys
|
||||
import traceback
|
||||
from concurrent.futures import Future
|
||||
from operator import attrgetter
|
||||
from threading import Thread
|
||||
from typing import Coroutine, Sequence
|
||||
|
||||
import nio
|
||||
from appdirs import AppDirs
|
||||
|
||||
import nio
|
||||
import pyotherside
|
||||
|
||||
from . import __about__
|
||||
@ -62,14 +63,15 @@ class App:
|
||||
|
||||
def _call_coro(self, coro: Coroutine, uuid: str) -> None:
|
||||
def on_done(future: Future) -> None:
|
||||
try:
|
||||
result = future.result()
|
||||
exception = None
|
||||
except Exception as err:
|
||||
result = None
|
||||
exception = err
|
||||
result = exception = trace = None
|
||||
|
||||
CoroutineDone(uuid, result, exception)
|
||||
try:
|
||||
result = future.result()
|
||||
except Exception as err:
|
||||
exception = err
|
||||
trace = traceback.format_exc().rstrip()
|
||||
|
||||
CoroutineDone(uuid, result, exception, trace)
|
||||
|
||||
self.run_in_loop(coro).add_done_callback(on_done)
|
||||
|
||||
|
@ -50,6 +50,7 @@ class CoroutineDone(PyOtherSideEvent):
|
||||
uuid: str = field()
|
||||
result: Any = None
|
||||
exception: Optional[Exception] = None
|
||||
traceback: Optional[str] = None
|
||||
|
||||
|
||||
@dataclass
|
||||
|
@ -13,7 +13,7 @@ function onAlertRequested() {
|
||||
}
|
||||
|
||||
|
||||
function onCoroutineDone(uuid, result, error) {
|
||||
function onCoroutineDone(uuid, result, error, traceback) {
|
||||
let onSuccess = py.pendingCoroutines[uuid].onSuccess
|
||||
let onError = py.pendingCoroutines[uuid].onError
|
||||
|
||||
@ -22,8 +22,8 @@ function onCoroutineDone(uuid, result, error) {
|
||||
let args = py.getattr(error, "args")
|
||||
|
||||
onError ?
|
||||
onError(type, args, error) :
|
||||
console.error(uuid + ": " + type + ": " + args)
|
||||
onError(type, args, error, traceback) :
|
||||
console.error("python:\n" + traceback)
|
||||
|
||||
} else if (onSuccess) { onSuccess(result) }
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user