Commit 1406463
authored
fix(conversation_tab): add resource cleanup when closing conversations (#1057)
* fix(conversation_tab): add resource cleanup when closing conversations
Add proper cleanup of all running resources when closing conversation tabs
or the application to prevent resource leaks, orphaned processes, and RuntimeErrors
from accessing destroyed widgets.
Resource cleanup improvements:
- Add cleanup_resources() method to ConversationTab for comprehensive cleanup
- Clean up completion handlers with skip_callbacks to prevent widget access
- Abort recording threads (instead of just stopping) to prevent transcription callbacks
- Stop progress sounds when closing tabs
- Terminate OCR processes gracefully with timeout and kill fallback
- Terminate background processes with proper error handling
- Add _is_destroying flag to prevent callbacks from accessing destroyed widgets
- Factorize cleanup logic with _cleanup_all_tabs() helper in MainFrame
- Call cleanup_resources() in on_close_conversation() and on_quit()
- Create _terminate_process() helper to factorize process termination logic
Defensive callback handling:
- Make all completion callbacks defensive (_on_completion_start, _on_completion_end,
_on_completion_error, _on_stream_chunk, _on_stream_start, _on_stream_finish,
_on_non_stream_finish) - check _is_destroying flag and widget existence
- Make all recording callbacks defensive (on_recording_started, on_recording_stopped,
on_transcription_started, on_transcription_received, on_transcription_error)
- Make OCR callbacks defensive (_handle_ocr_completion_message, _cleanup_ocr_process)
- Update RecordingThread to check _want_abort before scheduling callbacks
- Add skip_callbacks parameter to CompletionHandler.stop_completion()
- Improve stop_recording() with abort parameter and defensive UI updates
* fix(conversation_tab): address review comments
add stack traces to exception-related logs
Clear the recording_thread reference after aborting and joining the thread
in cleanup_resources() to allow proper garbage collection of the RecordingThread
and its held references (provider_engine, conversation_tab).
Fix _is_widget_valid() method to properly detect destroyed wx widgets by
removing the ineffective __class__ fallback and directly calling GetParent()
to trigger RuntimeError when the C++ peer has been destroyed.
Remove exc_info=True from log calls outside exception handlers
- Remove exc_info=True from log.debug/log.error calls that are not inside
exception handlers to prevent "NoneType: None" noise in logs
- Fixed in on_transcription_error(), _on_completion_error(),
_handle_ocr_completion_message(), and _enable_ocr_button()
- All remaining exc_info=True usages are correctly inside exception handlers
Add join() after kill() in process termination
- Add process.join(timeout=0.5) after process.kill() in _terminate_process()
to ensure killed processes are reaped before returning
- Prevents zombie processes from accumulating
- Guarded with hasattr and is_alive checks for safety
- Uses short timeout to avoid blocking
Add error handling to _cleanup_all_tabs1 parent 183809e commit 1406463
File tree
5 files changed
+291
-25
lines changed- basilisk
- gui
5 files changed
+291
-25
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
120 | 120 | | |
121 | 121 | | |
122 | 122 | | |
123 | | - | |
124 | | - | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
125 | 130 | | |
126 | 131 | | |
127 | 132 | | |
128 | 133 | | |
129 | 134 | | |
130 | | - | |
| 135 | + | |
131 | 136 | | |
132 | 137 | | |
133 | 138 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
152 | 152 | | |
153 | 153 | | |
154 | 154 | | |
| 155 | + | |
155 | 156 | | |
156 | 157 | | |
157 | 158 | | |
| |||
495 | 496 | | |
496 | 497 | | |
497 | 498 | | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
498 | 537 | | |
499 | 538 | | |
| 539 | + | |
| 540 | + | |
500 | 541 | | |
501 | 542 | | |
502 | 543 | | |
503 | 544 | | |
504 | 545 | | |
| 546 | + | |
| 547 | + | |
505 | 548 | | |
506 | 549 | | |
507 | 550 | | |
508 | 551 | | |
509 | 552 | | |
| 553 | + | |
| 554 | + | |
510 | 555 | | |
511 | 556 | | |
512 | 557 | | |
| |||
516 | 561 | | |
517 | 562 | | |
518 | 563 | | |
| 564 | + | |
| 565 | + | |
519 | 566 | | |
520 | 567 | | |
521 | 568 | | |
| |||
533 | 580 | | |
534 | 581 | | |
535 | 582 | | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
536 | 588 | | |
537 | 589 | | |
538 | 590 | | |
| |||
567 | 619 | | |
568 | 620 | | |
569 | 621 | | |
570 | | - | |
571 | | - | |
572 | | - | |
573 | | - | |
574 | | - | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
575 | 640 | | |
576 | 641 | | |
577 | 642 | | |
| |||
803 | 868 | | |
804 | 869 | | |
805 | 870 | | |
| 871 | + | |
| 872 | + | |
806 | 873 | | |
807 | 874 | | |
808 | 875 | | |
| |||
814 | 881 | | |
815 | 882 | | |
816 | 883 | | |
| 884 | + | |
| 885 | + | |
817 | 886 | | |
818 | 887 | | |
819 | 888 | | |
| |||
822 | 891 | | |
823 | 892 | | |
824 | 893 | | |
825 | | - | |
| 894 | + | |
| 895 | + | |
826 | 896 | | |
827 | 897 | | |
828 | 898 | | |
829 | 899 | | |
830 | 900 | | |
831 | 901 | | |
832 | 902 | | |
| 903 | + | |
| 904 | + | |
833 | 905 | | |
834 | 906 | | |
835 | 907 | | |
| |||
841 | 913 | | |
842 | 914 | | |
843 | 915 | | |
| 916 | + | |
| 917 | + | |
844 | 918 | | |
845 | 919 | | |
846 | 920 | | |
| |||
851 | 925 | | |
852 | 926 | | |
853 | 927 | | |
| 928 | + | |
| 929 | + | |
854 | 930 | | |
855 | 931 | | |
856 | 932 | | |
| |||
863 | 939 | | |
864 | 940 | | |
865 | 941 | | |
| 942 | + | |
| 943 | + | |
866 | 944 | | |
867 | 945 | | |
868 | 946 | | |
| |||
894 | 972 | | |
895 | 973 | | |
896 | 974 | | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
897 | 980 | | |
898 | 981 | | |
899 | | - | |
900 | 982 | | |
901 | 983 | | |
902 | 984 | | |
903 | 985 | | |
904 | 986 | | |
905 | 987 | | |
906 | 988 | | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
| 1014 | + | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
| 1036 | + | |
| 1037 | + | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
| 1046 | + | |
| 1047 | + | |
| 1048 | + | |
| 1049 | + | |
| 1050 | + | |
| 1051 | + | |
| 1052 | + | |
| 1053 | + | |
| 1054 | + | |
| 1055 | + | |
| 1056 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
403 | 403 | | |
404 | 404 | | |
405 | 405 | | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
406 | 427 | | |
407 | 428 | | |
408 | 429 | | |
| |||
419 | 440 | | |
420 | 441 | | |
421 | 442 | | |
422 | | - | |
| 443 | + | |
423 | 444 | | |
424 | 445 | | |
425 | 446 | | |
| |||
430 | 451 | | |
431 | 452 | | |
432 | 453 | | |
433 | | - | |
434 | | - | |
435 | | - | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
436 | 457 | | |
437 | 458 | | |
438 | 459 | | |
439 | 460 | | |
440 | 461 | | |
441 | 462 | | |
| 463 | + | |
442 | 464 | | |
443 | 465 | | |
444 | 466 | | |
| |||
611 | 633 | | |
612 | 634 | | |
613 | 635 | | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
614 | 639 | | |
615 | 640 | | |
616 | 641 | | |
617 | 642 | | |
618 | 643 | | |
619 | 644 | | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
620 | 658 | | |
621 | 659 | | |
| 660 | + | |
622 | 661 | | |
623 | 662 | | |
624 | 663 | | |
| |||
0 commit comments