fix backend not deallocating due to circular reference

This commit is contained in:
Damien Elmes 2020-03-03 21:12:14 +10:00
parent e9f4ac0e14
commit a8e6fbd0fd

View File

@ -176,6 +176,11 @@ def proto_progress_to_native(progress: pb.Progress) -> Progress:
else:
assert_impossible_literal(kind)
def _on_progress(progress_bytes: bytes) -> bool:
progress = pb.Progress()
progress.ParseFromString(progress_bytes)
native_progress = proto_progress_to_native(progress)
return hooks.bg_thread_progress_callback(True, native_progress)
class RustBackend:
def __init__(
@ -191,13 +196,7 @@ class RustBackend:
log_path=log_path,
)
self._backend = ankirspy.open_backend(init_msg.SerializeToString())
self._backend.set_progress_callback(self._on_progress)
def _on_progress(self, progress_bytes: bytes) -> bool:
progress = pb.Progress()
progress.ParseFromString(progress_bytes)
native_progress = proto_progress_to_native(progress)
return hooks.bg_thread_progress_callback(True, native_progress)
self._backend.set_progress_callback(_on_progress)
def _run_command(
self, input: pb.BackendInput, release_gil: bool = False