mirror of
https://github.com/ankitects/anki.git
synced 2025-09-25 01:06:35 -04:00
Log long-running calls on the UI thread
This commit is contained in:
parent
a7d7301d33
commit
6b3381afef
1 changed files with 8 additions and 0 deletions
|
@ -4,7 +4,9 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
import time
|
||||||
import traceback
|
import traceback
|
||||||
|
from threading import current_thread, main_thread
|
||||||
from typing import TYPE_CHECKING, Any, Iterable, Sequence
|
from typing import TYPE_CHECKING, Any, Iterable, Sequence
|
||||||
from weakref import ref
|
from weakref import ref
|
||||||
|
|
||||||
|
@ -148,10 +150,16 @@ class RustBackend(RustBackendGenerated):
|
||||||
return self.compute_fsrs_weights_from_items(items).weights
|
return self.compute_fsrs_weights_from_items(items).weights
|
||||||
|
|
||||||
def _run_command(self, service: int, method: int, input: bytes) -> bytes:
|
def _run_command(self, service: int, method: int, input: bytes) -> bytes:
|
||||||
|
start = time.time()
|
||||||
try:
|
try:
|
||||||
return self._backend.command(service, method, input)
|
return self._backend.command(service, method, input)
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
error_bytes = bytes(error.args[0])
|
error_bytes = bytes(error.args[0])
|
||||||
|
finally:
|
||||||
|
elapsed = time.time() - start
|
||||||
|
if current_thread() is main_thread() and elapsed > 0.2:
|
||||||
|
print(f"blocked main thread for {int(elapsed*1000)}ms:")
|
||||||
|
print("".join(traceback.format_stack()))
|
||||||
|
|
||||||
err = backend_pb2.BackendError()
|
err = backend_pb2.BackendError()
|
||||||
err.ParseFromString(error_bytes)
|
err.ParseFromString(error_bytes)
|
||||||
|
|
Loading…
Reference in a new issue